1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
|
<center><a href="petscctable.h">Actual source code: petscctable.h</a></center><br>
<html>
<head> <link rel="canonical" href="http://www.mcs.anl.gov/petsc/petsc-current/include/petscctable.h.html" />
<title></title>
<meta name="generator" content="c2html 0.9.4">
<meta name="date" content="2017-01-01T16:08:34+00:00">
</head>
<body bgcolor="#FFFFFF">
<div id="version" align=right><b>petsc-3.7.5 2017-01-01</b></div>
<div id="bugreport" align=right><a href="mailto:petsc-maint@mcs.anl.gov?subject=Typo or Error in Documentation &body=Please describe the typo or error in the documentation: petsc-3.7.5 v3.7.5 include/petscctable.h.html "><small>Report Typos and Errors</small></a></div>
<pre width="80"><a name="line1"> 1: </a><font color="#A020F0">#ifndef __PETSCCTABLE_H</font>
<a name="line3"> 3: </a><font color="#A020F0">#include <petscsys.h></font>
<a name="line5"> 5: </a><font color="#4169E1"><a name="_n_PetscTable"></a>struct _n_PetscTable </font>{
<a name="line6"> 6: </a> <a href="../docs/manualpages/Sys/PetscInt.html#PetscInt">PetscInt</a> *keytable;
<a name="line7"> 7: </a> <a href="../docs/manualpages/Sys/PetscInt.html#PetscInt">PetscInt</a> *table;
<a name="line8"> 8: </a> <a href="../docs/manualpages/Sys/PetscInt.html#PetscInt">PetscInt</a> count;
<a name="line9"> 9: </a> <a href="../docs/manualpages/Sys/PetscInt.html#PetscInt">PetscInt</a> tablesize;
<a name="line10"> 10: </a> <a href="../docs/manualpages/Sys/PetscInt.html#PetscInt">PetscInt</a> head;
<a name="line11"> 11: </a> <a href="../docs/manualpages/Sys/PetscInt.html#PetscInt">PetscInt</a> maxkey; <font color="#B22222">/* largest key allowed */</font>
<a name="line12"> 12: </a>};
<a name="line14"> 14: </a><font color="#4169E1">typedef struct _n_PetscTable* PetscTable;</font>
<a name="line15"> 15: </a><font color="#4169E1">typedef <a href="../docs/manualpages/Sys/PetscInt.html#PetscInt">PetscInt</a>* PetscTablePosition;</font>
<a name="line19"> 19: </a><strong><font color="#4169E1"><a name="PetscHash"></a>PETSC_STATIC_INLINE unsigned long PetscHash(PetscTable ta,unsigned long x)</font></strong>
<a name="line20"> 20: </a>{
<a name="line22"> 22: </a> <a href="../docs/manualpages/Sys/PetscFunctionReturn.html#PetscFunctionReturn">PetscFunctionReturn</a>(x%(unsigned long)ta->tablesize);
<a name="line23"> 23: </a>}
<a name="line27"> 27: </a><strong><font color="#4169E1"><a name="PetscHashStep"></a>PETSC_STATIC_INLINE unsigned long PetscHashStep(PetscTable ta,unsigned long x)</font></strong>
<a name="line28"> 28: </a>{
<a name="line30"> 30: </a> <a href="../docs/manualpages/Sys/PetscFunctionReturn.html#PetscFunctionReturn">PetscFunctionReturn</a>(1+(x%(unsigned long)(ta->tablesize-1)));
<a name="line31"> 31: </a>}
<a name="line33"> 33: </a><strong><font color="#4169E1">PETSC_EXTERN <a href="../docs/manualpages/Sys/PetscErrorCode.html#PetscErrorCode">PetscErrorCode</a> PetscTableCreate(const <a href="../docs/manualpages/Sys/PetscInt.html#PetscInt">PetscInt</a>,<a href="../docs/manualpages/Sys/PetscInt.html#PetscInt">PetscInt</a>,PetscTable*)</font></strong>;
<a name="line34"> 34: </a><strong><font color="#4169E1">PETSC_EXTERN <a href="../docs/manualpages/Sys/PetscErrorCode.html#PetscErrorCode">PetscErrorCode</a> PetscTableCreateCopy(const PetscTable,PetscTable*)</font></strong>;
<a name="line35"> 35: </a><strong><font color="#4169E1">PETSC_EXTERN <a href="../docs/manualpages/Sys/PetscErrorCode.html#PetscErrorCode">PetscErrorCode</a> PetscTableDestroy(PetscTable*)</font></strong>;
<a name="line36"> 36: </a><strong><font color="#4169E1">PETSC_EXTERN <a href="../docs/manualpages/Sys/PetscErrorCode.html#PetscErrorCode">PetscErrorCode</a> PetscTableGetCount(const PetscTable,<a href="../docs/manualpages/Sys/PetscInt.html#PetscInt">PetscInt</a>*)</font></strong>;
<a name="line37"> 37: </a><strong><font color="#4169E1">PETSC_EXTERN <a href="../docs/manualpages/Sys/PetscErrorCode.html#PetscErrorCode">PetscErrorCode</a> PetscTableIsEmpty(const PetscTable,<a href="../docs/manualpages/Sys/PetscInt.html#PetscInt">PetscInt</a>*)</font></strong>;
<a name="line38"> 38: </a><strong><font color="#4169E1">PETSC_EXTERN <a href="../docs/manualpages/Sys/PetscErrorCode.html#PetscErrorCode">PetscErrorCode</a> PetscTableAddExpand(PetscTable,<a href="../docs/manualpages/Sys/PetscInt.html#PetscInt">PetscInt</a>,<a href="../docs/manualpages/Sys/PetscInt.html#PetscInt">PetscInt</a>,<a href="../docs/manualpages/Sys/InsertMode.html#InsertMode">InsertMode</a>)</font></strong>;
<a name="line39"> 39: </a><strong><font color="#4169E1">PETSC_EXTERN <a href="../docs/manualpages/Sys/PetscErrorCode.html#PetscErrorCode">PetscErrorCode</a> PetscTableAddCountExpand(PetscTable,<a href="../docs/manualpages/Sys/PetscInt.html#PetscInt">PetscInt</a>)</font></strong>;
<a name="line40"> 40: </a><strong><font color="#4169E1">PETSC_EXTERN <a href="../docs/manualpages/Sys/PetscErrorCode.html#PetscErrorCode">PetscErrorCode</a> PetscTableGetHeadPosition(PetscTable,PetscTablePosition*)</font></strong>;
<a name="line41"> 41: </a><strong><font color="#4169E1">PETSC_EXTERN <a href="../docs/manualpages/Sys/PetscErrorCode.html#PetscErrorCode">PetscErrorCode</a> PetscTableGetNext(PetscTable,PetscTablePosition*,<a href="../docs/manualpages/Sys/PetscInt.html#PetscInt">PetscInt</a>*,<a href="../docs/manualpages/Sys/PetscInt.html#PetscInt">PetscInt</a>*)</font></strong>;
<a name="line42"> 42: </a><strong><font color="#4169E1">PETSC_EXTERN <a href="../docs/manualpages/Sys/PetscErrorCode.html#PetscErrorCode">PetscErrorCode</a> PetscTableRemoveAll(PetscTable)</font></strong>;
<a name="line46"> 46: </a><strong><font color="#4169E1"><a name="PetscTableAdd"></a>PETSC_STATIC_INLINE <a href="../docs/manualpages/Sys/PetscErrorCode.html#PetscErrorCode">PetscErrorCode</a> PetscTableAdd(PetscTable ta,<a href="../docs/manualpages/Sys/PetscInt.html#PetscInt">PetscInt</a> key,<a href="../docs/manualpages/Sys/PetscInt.html#PetscInt">PetscInt</a> data,<a href="../docs/manualpages/Sys/InsertMode.html#InsertMode">InsertMode</a> imode)</font></strong>
<a name="line47"> 47: </a>{
<a name="line49"> 49: </a> <a href="../docs/manualpages/Sys/PetscInt.html#PetscInt">PetscInt</a> i,hash = (<a href="../docs/manualpages/Sys/PetscInt.html#PetscInt">PetscInt</a>)PetscHash(ta,(unsigned long)key);
<a name="line50"> 50: </a> <a href="../docs/manualpages/Sys/PetscInt.html#PetscInt">PetscInt</a> hashstep = (<a href="../docs/manualpages/Sys/PetscInt.html#PetscInt">PetscInt</a>)PetscHashStep(ta,(unsigned long)key);
<a name="line53"> 53: </a> <font color="#4169E1">if</font> (key <= 0) <a href="../docs/manualpages/Sys/SETERRQ.html#SETERRQ">SETERRQ</a>(<a href="../docs/manualpages/Sys/PETSC_COMM_SELF.html#PETSC_COMM_SELF">PETSC_COMM_SELF</a>,PETSC_ERR_ARG_OUTOFRANGE,<font color="#666666">"key <= 0"</font>);
<a name="line54"> 54: </a> <font color="#4169E1">if</font> (key > ta->maxkey) <a href="../docs/manualpages/Sys/SETERRQ2.html#SETERRQ2">SETERRQ2</a>(<a href="../docs/manualpages/Sys/PETSC_COMM_SELF.html#PETSC_COMM_SELF">PETSC_COMM_SELF</a>,PETSC_ERR_ARG_OUTOFRANGE,<font color="#666666">"key %D is greater than largest key allowed %D"</font>,key,ta->maxkey);
<a name="line55"> 55: </a> <font color="#4169E1">if</font> (!data) <a href="../docs/manualpages/Sys/SETERRQ.html#SETERRQ">SETERRQ</a>(<a href="../docs/manualpages/Sys/PETSC_COMM_SELF.html#PETSC_COMM_SELF">PETSC_COMM_SELF</a>,PETSC_ERR_ARG_OUTOFRANGE,<font color="#666666">"Null data"</font>);
<a name="line57"> 57: </a> <font color="#4169E1">for</font> (i=0; i<ta->tablesize; i++) {
<a name="line58"> 58: </a> <font color="#4169E1">if</font> (ta->keytable[hash] == key) {
<a name="line59"> 59: </a> <font color="#4169E1">switch</font> (imode) {
<a name="line60"> 60: </a> <font color="#4169E1">case</font> <a href="../docs/manualpages/Sys/INSERT_VALUES.html#INSERT_VALUES">INSERT_VALUES</a>:
<a name="line61"> 61: </a> ta->table[hash] = data; <font color="#B22222">/* over write */</font>
<a name="line62"> 62: </a> <font color="#4169E1">break</font>;
<a name="line63"> 63: </a> <font color="#4169E1">case</font> <a href="../docs/manualpages/Sys/ADD_VALUES.html#ADD_VALUES">ADD_VALUES</a>:
<a name="line64"> 64: </a> ta->table[hash] += data;
<a name="line65"> 65: </a> <font color="#4169E1">break</font>;
<a name="line66"> 66: </a> <font color="#4169E1">case</font> <a href="../docs/manualpages/Sys/MAX_VALUES.html#MAX_VALUES">MAX_VALUES</a>:
<a name="line67"> 67: </a> ta->table[hash] = <a href="../docs/manualpages/Sys/PetscMax.html#PetscMax">PetscMax</a>(ta->table[hash],data);
<a name="line68"> 68: </a> <font color="#4169E1">break</font>;
<a name="line69"> 69: </a> <font color="#4169E1">case</font> NOT_SET_VALUES:
<a name="line70"> 70: </a> <font color="#4169E1">case</font> INSERT_ALL_VALUES:
<a name="line71"> 71: </a> <font color="#4169E1">case</font> ADD_ALL_VALUES:
<a name="line72"> 72: </a> <font color="#4169E1">case</font> INSERT_BC_VALUES:
<a name="line73"> 73: </a> <font color="#4169E1">case</font> ADD_BC_VALUES:
<a name="line74"> 74: </a> <a href="../docs/manualpages/Sys/SETERRQ.html#SETERRQ">SETERRQ</a>(<a href="../docs/manualpages/Sys/PETSC_COMM_SELF.html#PETSC_COMM_SELF">PETSC_COMM_SELF</a>,PETSC_ERR_SUP,<font color="#666666">"Unsupported <a href="../docs/manualpages/Sys/InsertMode.html#InsertMode">InsertMode</a>"</font>);
<a name="line75"> 75: </a> }
<a name="line76"> 76: </a> <font color="#4169E1">return</font>(0);
<a name="line77"> 77: </a> } <font color="#4169E1">else</font> <font color="#4169E1">if</font> (!ta->keytable[hash]) {
<a name="line78"> 78: </a> <font color="#4169E1">if</font> (ta->count < 5*(ta->tablesize/6) - 1) {
<a name="line79"> 79: </a> ta->count++; <font color="#B22222">/* add */</font>
<a name="line80"> 80: </a> ta->keytable[hash] = key;
<a name="line81"> 81: </a> ta->table[hash] = data;
<a name="line82"> 82: </a> } <font color="#4169E1">else</font> {
<a name="line83"> 83: </a> PetscTableAddExpand(ta,key,data,imode);
<a name="line84"> 84: </a> }
<a name="line85"> 85: </a> <font color="#4169E1">return</font>(0);
<a name="line86"> 86: </a> }
<a name="line87"> 87: </a> hash = (hash + hashstep)%ta->tablesize;
<a name="line88"> 88: </a> }
<a name="line89"> 89: </a> <a href="../docs/manualpages/Sys/SETERRQ.html#SETERRQ">SETERRQ</a>(<a href="../docs/manualpages/Sys/PETSC_COMM_SELF.html#PETSC_COMM_SELF">PETSC_COMM_SELF</a>,PETSC_ERR_COR,<font color="#666666">"Full table"</font>);
<a name="line90"> 90: </a> <font color="#B22222">/* return(0); */</font>
<a name="line91"> 91: </a>}
<a name="line95"> 95: </a><strong><font color="#4169E1"><a name="PetscTableAddCount"></a>PETSC_STATIC_INLINE <a href="../docs/manualpages/Sys/PetscErrorCode.html#PetscErrorCode">PetscErrorCode</a> PetscTableAddCount(PetscTable ta,<a href="../docs/manualpages/Sys/PetscInt.html#PetscInt">PetscInt</a> key)</font></strong>
<a name="line96"> 96: </a>{
<a name="line98"> 98: </a> <a href="../docs/manualpages/Sys/PetscInt.html#PetscInt">PetscInt</a> i,hash = (<a href="../docs/manualpages/Sys/PetscInt.html#PetscInt">PetscInt</a>)PetscHash(ta,(unsigned long)key);
<a name="line99"> 99: </a> <a href="../docs/manualpages/Sys/PetscInt.html#PetscInt">PetscInt</a> hashstep = (<a href="../docs/manualpages/Sys/PetscInt.html#PetscInt">PetscInt</a>)PetscHashStep(ta,(unsigned long)key);
<a name="line102">102: </a> <font color="#4169E1">if</font> (key <= 0) <a href="../docs/manualpages/Sys/SETERRQ.html#SETERRQ">SETERRQ</a>(<a href="../docs/manualpages/Sys/PETSC_COMM_SELF.html#PETSC_COMM_SELF">PETSC_COMM_SELF</a>,PETSC_ERR_ARG_OUTOFRANGE,<font color="#666666">"key <= 0"</font>);
<a name="line103">103: </a> <font color="#4169E1">if</font> (key > ta->maxkey) <a href="../docs/manualpages/Sys/SETERRQ2.html#SETERRQ2">SETERRQ2</a>(<a href="../docs/manualpages/Sys/PETSC_COMM_SELF.html#PETSC_COMM_SELF">PETSC_COMM_SELF</a>,PETSC_ERR_ARG_OUTOFRANGE,<font color="#666666">"key %D is greater than largest key allowed %D"</font>,key,ta->maxkey);
<a name="line105">105: </a> <font color="#4169E1">for</font> (i=0; i<ta->tablesize; i++) {
<a name="line106">106: </a> <font color="#4169E1">if</font> (ta->keytable[hash] == key) {
<a name="line107">107: </a> <font color="#4169E1">return</font>(0);
<a name="line108">108: </a> } <font color="#4169E1">else</font> <font color="#4169E1">if</font> (!ta->keytable[hash]) {
<a name="line109">109: </a> <font color="#4169E1">if</font> (ta->count < 5*(ta->tablesize/6) - 1) {
<a name="line110">110: </a> ta->count++; <font color="#B22222">/* add */</font>
<a name="line111">111: </a> ta->keytable[hash] = key;
<a name="line112">112: </a> ta->table[hash] = ta->count;
<a name="line113">113: </a> } <font color="#4169E1">else</font> {
<a name="line114">114: </a> PetscTableAddCountExpand(ta,key);
<a name="line115">115: </a> }
<a name="line116">116: </a> <font color="#4169E1">return</font>(0);
<a name="line117">117: </a> }
<a name="line118">118: </a> hash = (hash + hashstep)%ta->tablesize;
<a name="line119">119: </a> }
<a name="line120">120: </a> <a href="../docs/manualpages/Sys/SETERRQ.html#SETERRQ">SETERRQ</a>(<a href="../docs/manualpages/Sys/PETSC_COMM_SELF.html#PETSC_COMM_SELF">PETSC_COMM_SELF</a>,PETSC_ERR_COR,<font color="#666666">"Full table"</font>);
<a name="line121">121: </a> <font color="#B22222">/* return(0); */</font>
<a name="line122">122: </a>}
<a name="line127">127: </a><font color="#B22222">/*</font>
<a name="line128">128: </a><font color="#B22222"> PetscTableFind - checks if a key is in the table</font>
<a name="line130">130: </a><font color="#B22222"> If data==0, then no table entry exists.</font>
<a name="line132">132: </a><font color="#B22222">*/</font>
<a name="line133">133: </a><strong><font color="#4169E1"><a name="PetscTableFind"></a>PETSC_STATIC_INLINE <a href="../docs/manualpages/Sys/PetscErrorCode.html#PetscErrorCode">PetscErrorCode</a> PetscTableFind(PetscTable ta,<a href="../docs/manualpages/Sys/PetscInt.html#PetscInt">PetscInt</a> key,<a href="../docs/manualpages/Sys/PetscInt.html#PetscInt">PetscInt</a> *data)</font></strong>
<a name="line134">134: </a>{
<a name="line135">135: </a> <a href="../docs/manualpages/Sys/PetscInt.html#PetscInt">PetscInt</a> ii = 0;
<a name="line136">136: </a> <a href="../docs/manualpages/Sys/PetscInt.html#PetscInt">PetscInt</a> hash = (<a href="../docs/manualpages/Sys/PetscInt.html#PetscInt">PetscInt</a>)PetscHash(ta,(unsigned long)key);
<a name="line137">137: </a> <a href="../docs/manualpages/Sys/PetscInt.html#PetscInt">PetscInt</a> hashstep = (<a href="../docs/manualpages/Sys/PetscInt.html#PetscInt">PetscInt</a>)PetscHashStep(ta,(unsigned long)key);
<a name="line140">140: </a> *data = 0;
<a name="line141">141: </a> <font color="#4169E1">if</font> (key <= 0) <a href="../docs/manualpages/Sys/SETERRQ.html#SETERRQ">SETERRQ</a>(<a href="../docs/manualpages/Sys/PETSC_COMM_SELF.html#PETSC_COMM_SELF">PETSC_COMM_SELF</a>,PETSC_ERR_ARG_OUTOFRANGE,<font color="#666666">"Key <= 0"</font>);
<a name="line142">142: </a> <font color="#4169E1">if</font> (key > ta->maxkey) <a href="../docs/manualpages/Sys/SETERRQ2.html#SETERRQ2">SETERRQ2</a>(<a href="../docs/manualpages/Sys/PETSC_COMM_SELF.html#PETSC_COMM_SELF">PETSC_COMM_SELF</a>,PETSC_ERR_ARG_OUTOFRANGE,<font color="#666666">"key %D is greater than largest key allowed %D"</font>,key,ta->maxkey);
<a name="line144">144: </a> <font color="#4169E1">while</font> (ii++ < ta->tablesize) {
<a name="line145">145: </a> <font color="#4169E1">if</font> (!ta->keytable[hash]) <font color="#4169E1">break</font>;
<a name="line146">146: </a> <font color="#4169E1">else</font> <font color="#4169E1">if</font> (ta->keytable[hash] == key) {
<a name="line147">147: </a> *data = ta->table[hash];
<a name="line148">148: </a> <font color="#4169E1">break</font>;
<a name="line149">149: </a> }
<a name="line150">150: </a> hash = (hash + hashstep)%ta->tablesize;
<a name="line151">151: </a> }
<a name="line152">152: </a> <font color="#4169E1">return</font>(0);
<a name="line153">153: </a>}
<a name="line155">155: </a><font color="#B22222">/* Reset __FUNCT__ in case the user does not define it themselves */</font>
<a name="line159">159: </a><font color="#A020F0">#endif</font>
</pre>
</body>
</html>
|