public TValue ExtractMin() { Debug.Assert(_initialized); int hMin = _nodes[1]; TValue min = _handles[hMin]._key; if (_size > 0) { _nodes[1] = _nodes[_size]; _handles[_nodes[1]].SetNode(1); _handles[hMin] = new HandleElem { _key = null, _node = _freeList }; _freeList = hMin; if (--_size > 0) { FloatDown(1); } } return(min); }
public void Remove(PQHandle handle) { Debug.Assert(_initialized); int hCurr = handle._handle; Debug.Assert(hCurr >= 1 && hCurr <= _max && _handles[hCurr]._key != null); int curr = _handles[hCurr]._node; _nodes[curr] = _nodes[_size]; _handles[_nodes[curr]].SetNode(curr); if (curr <= --_size) { if (curr <= 1 || _leq(_handles[_nodes[curr >> 1]]._key, _handles[_nodes[curr]]._key)) { FloatDown(curr); } else { FloatUp(curr); } } _handles[hCurr] = new HandleElem { _key = null, _node = _freeList }; _freeList = hCurr; }
public PQHandle Insert(TValue value) { int curr = ++_size; if (curr * 2 > _max) { _max <<= 1; Array.Resize(ref _nodes, _max + 1); Array.Resize(ref _handles, _max + 1); } int free; switch (_freeList) { case 0: free = curr; break; default: free = _freeList; _freeList = _handles[free]._node; break; } _nodes[curr] = free; switch (_handles[free]) { case null: _handles[free] = new HandleElem { _key = value, _node = curr }; break; default: _handles[free]._node = curr; _handles[free]._key = value; break; } switch (_initialized) { case true: FloatUp(curr); break; } Debug.Assert(free != PQHandle.Invalid); return(new PQHandle { _handle = free }); }
public VertexPriorityHeap(int initialSize) { _nodes = ArrayPool<int>.Create(initialSize + 1, true); _handles = ArrayPool<HandleElem>.Create(initialSize + 1, true); _size = 0; _max = initialSize; _freeList = 0; _initialized = false; _nodes[1] = 1; _handles[1] = new HandleElem { _key = null }; }
public PriorityHeap(int initialSize, LessOrEqual leq) { _leq = leq; _nodes = new int[initialSize + 1]; _handles = new HandleElem[initialSize + 1]; _size = 0; _max = initialSize; _freeList = 0; _initialized = false; _nodes[1] = 1; _handles[1] = new HandleElem { _key = null }; }
public VertexPriorityHeap(int initialSize) { _nodes = ArrayPool <int> .Create(initialSize + 1, true); _handles = ArrayPool <HandleElem> .Create(initialSize + 1, true); _size = 0; _max = initialSize; _freeList = 0; _initialized = false; _nodes[1] = 1; _handles[1] = new HandleElem { _key = null }; }
public PQHandle Insert(TValue value) { int curr = ++_size; if ((curr * 2) > _max) { _max <<= 1; Array.Resize(ref _nodes, _max + 1); Array.Resize(ref _handles, _max + 1); } int free; if (_freeList == 0) { free = curr; } else { free = _freeList; _freeList = _handles[free]._node; } _nodes[curr] = free; if (_handles[free] == null) { _handles[free] = new HandleElem { _key = value, _node = curr }; } else { _handles[free]._node = curr; _handles[free]._key = value; } if (_initialized) { FloatUp(curr); } Debug.Assert(free != PQHandle.Invalid); return(new PQHandle { _handle = free }); }
internal int Insert(MeshUtils.Vertex value) { int curr = ++_size; if ((curr * 2) > _max) { _max <<= 1; ArrayPool <int> .Resize(ref _nodes, _max + 1, true); ArrayPool <HandleElem> .Resize(ref _handles, _max + 1, true); } int free; if (_freeList == 0) { free = curr; } else { free = _freeList; _freeList = _handles[free]._node; } _nodes[curr] = free; if (_handles[free] == null) { _handles[free] = new HandleElem { _key = value, _node = curr }; } else { _handles[free]._node = curr; _handles[free]._key = value; } if (_initialized) { FloatUp(curr); } Debug.Assert(free != PQHandle.Invalid); return(free); }
public PQHandle Insert(TValue value) { int num = ++_size; if (num * 2 > _max) { _max <<= 1; Array.Resize(ref _nodes, _max + 1); Array.Resize(ref _handles, _max + 1); } int num2; if (_freeList == 0) { num2 = num; } else { num2 = _freeList; _freeList = _handles[num2]._node; } _nodes[num] = num2; if (_handles[num2] == null) { _handles[num2] = new HandleElem { _key = value, _node = num }; } else { _handles[num2]._node = num; _handles[num2]._key = value; } if (_initialized) { FloatUp(num); } PQHandle result = default(PQHandle); result._handle = num2; return(result); }
public PQHandle Insert(TValue value) { int curr = ++_size; if ((curr * 2) > _max) { _max <<= 1; _nodes.AddRange(new int[_max + 1 - _nodes.Count]); _handles.AddRange(new HandleElem[_max + 1 - _handles.Count]); } int free; if (_freeList == 0) { free = curr; } else { free = _freeList; _freeList = _handles[free]._node; } _nodes[curr] = free; _handles[free] = new HandleElem { _key = value, _node = curr }; if (_initialized) { FloatUp(curr); } Debug.Assert(free != PQHandle.Invalid); return(new PQHandle { _handle = free }); }
public void Reset(int initialSize, LessOrEqual leq) { _leq = leq; if (_nodes.Count < initialSize + 1) { _nodes.AddRange(new int[initialSize + 1 - _nodes.Count]); } if (_handles.Count < initialSize + 1) { _handles.AddRange(new HandleElem[initialSize + 1 - _handles.Count]); } _size = 0; _max = initialSize; _freeList = 0; _initialized = false; _nodes[1] = 1; _handles[1] = new HandleElem { _key = null }; }
internal PQHandle Insert(MeshUtils.Vertex value) { int curr = ++_size; if ((curr * 2) > _max) { _max <<= 1; ArrayPool<int>.Resize(ref _nodes, _max + 1, true); ArrayPool<HandleElem>.Resize(ref _handles, _max + 1, true); } int free; if (_freeList == 0) { free = curr; } else { free = _freeList; _freeList = _handles[free]._node; } _nodes[curr] = free; if (_handles[free] == null) { _handles[free] = new HandleElem { _key = value, _node = curr }; } else { _handles[free]._node = curr; _handles[free]._key = value; } if (_initialized) { FloatUp(curr); } Debug.Assert(free != PQHandle.Invalid); return new PQHandle { _handle = free }; }