MCPcopy Create free account
hub / github.com/OpenSees/OpenSees / PQueueInsert

Function PQueueInsert

OTHER/METIS/pqueue.c:139–191  ·  view source on GitHub ↗

* This function adds a node of certain gain into a partition **************************************************************************/

Source from the content-addressed store, hash-verified

137* This function adds a node of certain gain into a partition
138**************************************************************************/
139int PQueueInsert(PQueueType *queue, int node, int gain)
140{
141 int i, j, k;
142 idxtype *locator;
143 ListNodeType *newnode;
144 KeyValueType *heap;
145
146 if (queue->type == 1) {
147 ASSERT(gain >= -queue->ngainspan && gain <= queue->pgainspan);
148
149 /* Allocate and add the node */
150 queue->nnodes++;
151 newnode = queue->nodes + node;
152
153 /* Attach this node in the doubly-linked list */
154 newnode->next = queue->buckets[gain];
155 newnode->prev = NULL;
156 if (newnode->next != NULL)
157 newnode->next->prev = newnode;
158 queue->buckets[gain] = newnode;
159
160 if (queue->maxgain < gain)
161 queue->maxgain = gain;
162 }
163 else {
164 ASSERT(CheckHeap(queue));
165
166 heap = queue->heap;
167 locator = queue->locator;
168
169 ASSERT(locator[node] == -1);
170
171 i = queue->nnodes++;
172 while (i > 0) {
173 j = (i-1)/2;
174 if (heap[j].key < gain) {
175 heap[i] = heap[j];
176 locator[heap[i].val] = i;
177 i = j;
178 }
179 else
180 break;
181 }
182 ASSERT(i >= 0);
183 heap[i].key = gain;
184 heap[i].val = node;
185 locator[node] = i;
186
187 ASSERT(CheckHeap(queue));
188 }
189
190 return 0;
191}
192
193
194/*************************************************************************

Callers 15

MocGeneral2WayBalance2Function · 0.85
MocGeneral2WayBalanceFunction · 0.85
PQueueUpdateFunction · 0.85
MocFM_2WayEdgeRefineFunction · 0.85
Greedy_KWayVolBalanceFunction · 0.85
Greedy_KWayEdgeRefineFunction · 0.85
Greedy_KWayEdgeBalanceFunction · 0.85
FM_2WayNodeRefineFunction · 0.85
FM_2WayNodeRefine2Function · 0.85
FM_2WayNodeRefineEqWgtFunction · 0.85

Calls 1

CheckHeapFunction · 0.85

Tested by

no test coverage detected