How to use the heap.pushpop function in heap

To help you get started, we’ve selected a few heap examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mayconbordin / node-datastream / lib / counter / countmin-sketch.js View on Github external
updateHeap: function(key) {
        var estimate = this.get(key);
        
        if (this.heap.length == 0 || estimate >= this.heap[0].value) {
            if (key in this.topK) {
                var oldPair = this.topK[key];
                oldPair.value = estimate;
                Heap.heapify(this.heap);
            } else {
                if (fn.objSize(this.topK) < this.k) {
                    Heap.push(this.heap, {key: key, value: estimate});
                    this.topK[key] = {key: key, value: estimate};
                    this.topKSize++;
                } else {
                    var newPair = {key: key, value: estimate};
                    var oldPair = Heap.pushpop(this.heap, newPair);
                    delete this.topK[oldPair[1]];
                    this.topK[key] = newPair;
                }
            }
        }
    },

heap

binary heap (priority queue) algorithms (ported from Python's heapq module)

MIT
Latest version published 3 years ago

Package Health Score

67 / 100
Full package analysis