Find smallest item after removing deleted items from front of heap.
359692
def smallest(self):
        '''
        
        '''
        if len(self) == 0:
            raise IndexError, "smallest of empty priorityDictionary"
        heap = self.__heap
        while heap[0][1] not in self or self[heap[0][1]] != heap[0][0]:
            lastItem = heap.pop()
            insertionPoint = 0
            while 1:
                smallChild = 2*insertionPoint+1
                if smallChild+1 < len(heap) and heap[smallChild] > heap[smallChild+1] :
                    smallChild += 1
                if smallChild >= len(heap) or lastItem <= heap[smallChild]:
                    heap[insertionPoint] = lastItem
                    break
                heap[insertionPoint] = heap[smallChild]
                insertionPoint = smallChild
        return heap[0][1]
1328297
def siftdown(heap1, heap2, elt):
    """"""
    while elt * 2 + 1 < heap1.shape[0]:
        left_child = elt * 2 + 1
        right_child = left_child + 1
        swap = elt

        if heap1[swap] < heap1[left_child]:
            swap = left_child

        if right_child < heap1.shape[0] and heap1[swap] < heap1[right_child]:
            swap = right_child

        if swap == elt:
            break
        else:
            heap1[elt], heap1[swap] = heap1[swap], heap1[elt]
            heap2[elt], heap2[swap] = heap2[swap], heap2[elt]
            elt = swap
1319208
def findPreviousItem(self, item):
        
        if not item:
            return None
        
        while item.parent():
            index = item.parent().indexOfChild(item)
            if index == 0:
                return item.parent()
            
            child = item.parent().child(index-1)
            if child:
                while child.childCount():
                    child = child.child(child.childCount() - 1)
                return child
            
            item = item.parent()
        
        index = self.indexOfTopLevelItem(item)
        out = self.topLevelItem(index-1)
        while out and out.childCount():
            out = out.child(out.childCount() - 1)
        return out
271599
def lastIndexOf(self, item):
        
        array = self.obj
        i = len(array) - 1
        if not (self._clean.isList() or self._clean.isTuple()):
            return self._wrap(-1)

        while i > -1:
            if array[i] is item:
                return self._wrap(i)
            i -= 1
        return self._wrap(-1)
1048384
def heappush(heap, item):
    """"""
    heap.append(item)
    _siftdown(heap, 0, len(heap)-1)
745201
private T doRemove(int index) {
        keys[index]   = 0;
        states[index] = REMOVED;
        final Object previous = values[index];
        values[index] = missingEntries;
        --size;
        ++count;
        return (T)previous;
    }
170153
private long findAfter(long offset) {
    if (size == 0) {
      return -1;
    }

    int low  = 0;
    int high = size-1;

    while (low <= high) {
      int mid = low + ((high - low) / 2);

      long i = buffer.readLong(mid * ENTRY_SIZE);
      if (i < offset) {
        low = mid + 1;
      } else if (i > offset) {
        high = mid - 1;
      } else {
        return mid;
      }
    }

    return (low < high) ? low + 1 : high + 1;
  }
1131357
def last_n_items(array, n_desired):
    """"""
    # Unfortunately, we can't just do array.flat[-n_desired:] here because it
    # might not be a numpy.ndarray. Moreover, access to elements of the array
    # could be very expensive (e.g. if it's only available over DAP), so go out
    # of our way to get them in a single call to __getitem__ using only slices.
    if (n_desired == 0) or (array.size == 0):
        return []

    if n_desired < array.size:
        indexer = _get_indexer_at_least_n_items(array.shape, n_desired,
                                                from_end=True)
        array = array[indexer]
    return np.asarray(array).flat[-n_desired:]
80306
def delete(self, item):
        
        indexer = self.items.get_loc(item)

        is_deleted = np.zeros(self.shape[0], dtype=np.bool_)
        is_deleted[indexer] = True
        ref_loc_offset = -is_deleted.cumsum()

        is_blk_deleted = [False] * len(self.blocks)

        if isinstance(indexer, int):
            affected_start = indexer
        else:
            affected_start = is_deleted.nonzero()[0][0]

        for blkno, _ in _fast_count_smallints(self._blknos[affected_start:]):
            blk = self.blocks[blkno]
            bml = blk.mgr_locs
            blk_del = is_deleted[bml.indexer].nonzero()[0]

            if len(blk_del) == len(bml):
                is_blk_deleted[blkno] = True
                continue
            elif len(blk_del) != 0:
                blk.delete(blk_del)
                bml = blk.mgr_locs

            blk.mgr_locs = bml.add(ref_loc_offset[bml.indexer])

        # FIXME: use Index.delete as soon as it uses fastpath=True
        self.axes[0] = self.items[~is_deleted]
        self.blocks = tuple(b for blkno, b in enumerate(self.blocks)
                            if not is_blk_deleted[blkno])
        self._shape = None
        self._rebuild_blknos_and_blklocs()
671372
private int findMin(Comparator comparator, int index, int len)
  {
    if (index >= heapSize) {
      return -1;
    }
    int limit = Math.min(index, heapSize - len) + len;
    int minIndex = index;
    for (int i = index + 1; i < limit; i++) {
      if (comparator.compare(buf.getInt(i * Integer.BYTES), buf.getInt(minIndex * Integer.BYTES)) < 0) {
        minIndex = i;
      }
    }
    return minIndex;
  }
710285
private void findAndCacheMinimum(int firstBucket) {
        if (currentMin == null) {
            // find first non-empty bucket
            currentMinBucket = EMPTY;
            for (int i = firstBucket; i < this.buckets.length; i++) {
                if (!buckets[i].isEmpty()) {
                    currentMinBucket = i;
                    break;
                }
            }
            // find new minimum and its position (beware of cached values)
            currentMinPos = EMPTY;
            if (currentMinBucket >= 0) {
                int pos = 0;
                for (K val : buckets[currentMinBucket]) {
                    if (currentMin == null || compare(val, currentMin) < 0) {
                        currentMin = val;
                        currentMinPos = pos;
                    }
                    ++pos;
                }
            }
        }
    }
1019064
def heappop(heap):
    """"""
    lastelt = heap.pop()    # raises appropriate IndexError if heap is empty
    if heap:
        returnitem = heap[0]
        heap[0] = lastelt
        _siftup(heap, 0)
        return returnitem
    return lastelt
825476
private void minimize() {

        // Algorithm: compare each entry n to all subsequent entries in
        // the list: if any subsequent entry matches or widens entry n,
        // remove entry n. If any subsequent entries narrow entry n, remove
        // the subsequent entries.
        for (int i = 0; i < size(); i++) {
            GeneralNameInterface current = getGeneralNameInterface(i);
            boolean remove1 = false;

            /* compare current to subsequent elements */
            for (int j = i + 1; j < size(); j++) {
                GeneralNameInterface subsequent = getGeneralNameInterface(j);
                switch (current.constrains(subsequent)) {
                    case GeneralNameInterface.NAME_DIFF_TYPE:
                        /* not comparable; different name types; keep checking */
                        continue;
                    case GeneralNameInterface.NAME_MATCH:
                        /* delete one of the duplicates */
                        remove1 = true;
                        break;
                    case GeneralNameInterface.NAME_NARROWS:
                        /* subsequent narrows current */
                        /* remove narrower name (subsequent) */
                        remove(j);
                        j--; /* continue check with new subsequent */
                        continue;
                    case GeneralNameInterface.NAME_WIDENS:
                        /* subsequent widens current */
                        /* remove narrower name current */
                        remove1 = true;
                        break;
                    case GeneralNameInterface.NAME_SAME_TYPE:
                        /* keep both for now; keep checking */
                        continue;
                }
                break;
            } /* end of this pass of subsequent elements */

            if (remove1) {
                remove(i);
                i--; /* check the new i value */
            }

        }
    }
1280349
private void findDelete(
                           DeleteNode        point,
                           DeleteStack       stack,
                           Object            deleteKey)
    {
        java.util.Comparator comp = deleteComparator();
        GBSNode       p;               /* P is used to march down the tree      */
        int           xcc;             /* Compare result                        */
        GBSNode       l_last = null;   /* Node from which we last departed by   */
                                       /*  turning left (logical successor)     */
        GBSNode       r_last = null;   /* Node from which we last departed by   */
                                       /*  turning right (logical predecessor)  */
        p = root();                    /* Root of tree                          */
                                       /* Remember father of root               */
        stack.start(dummyTopNode(), "GBSTree.findDelete");

        while (p != null)
        {
            xcc = comp.compare(deleteKey, p.middleKey());
            if (xcc == 0)                /* Delete key = median key               */
            {
                midDelete(stack, p, point);
                p = null;
            }
            else if (xcc < 0)            /* Delete key < median key               */
            {
                if (p.leftChild() != null)
                {
                    l_last = p;          /* Remember node from which we           */
                                         /*  last moved left (successor)          */
                    stack.push(NodeStack.PROCESS_CURRENT, p, "GBSTree.findDelete(1)");
                    p = p.leftChild();
                }
                else                     /* There is no left child                */
                {
                    /* Delete on left side                   */
                    leftDelete(p, r_last, deleteKey, point);
                    p = null;
                }
            }
            else                         /* Delete key > median key               */
            {
                if (p.rightChild() != null)
                {
                    r_last = p;          /* Remember node from which we           */
                                         /*  last moved right (predecessor)       */
                    stack.push(NodeStack.DONE_VISITS, p, "GBSTree.findDelete(2)");
                    p = p.rightChild();
                }
                else                     /* There is no right child               */
                {
                    rightDelete(p, l_last, deleteKey, point);
                    p = null;
                }
            }
        }
    }
1223260
int findDeleteInRight(
    Object           delKey)
  {
    int idx = -1;
    int r = rightMostIndex();
    int m = midPoint();
    if (r > m)
      idx = findDelete(m, r, delKey);
    return idx;
  }
905209
function smallest (arr, compare) {
		var n = arr.length;
		if (!n) { return; }

		var min = arr[0];
		for (var k = 1; k < n; k++){
			if (compare(arr[k], min) == -1) {
				min = arr[k];
			}
		}

		return min;
	}
1049463
function (items) {
                var
                    idx;
                idx = items.length;
                while (idx--) {
                    if (0 !== items[idx].min()) {
                        ++idx;
                        break;
                    }
                }
                return idx;
            }