How to use the mnemonist/heap function in mnemonist

To help you get started, we’ve selected a few mnemonist 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 Yomguithereal / talisman / src / keyword-extraction / rake.js View on Github external
}
        }
        else {

          // Updating word frequency
          wordFrequencies[word] = wordFrequencies[word] || 0;
          wordFrequencies[word]++;

          // Adding the word to the current keyword
          keyword.push(word);
        }
      }
    }

    // Now we need to score the keywords and retrieve the best one
    const heap = new Heap(comparator),
          T = (candidateKeywords.size / 3) | 0;

    candidateKeywords.forEach(keyword => {
      const words = keyword.split(HASH_DELIMITER);
      let score = 0;

      for (let i = 0, l = words.length; i < l; i++) {
        const word = words[i];
        score += wordDegrees[word] / wordFrequencies[word];
      }

      heap.push({score, keyword: words});

      if (heap.size > T)
        heap.pop();
    });
github Yomguithereal / talisman / src / structures / vp-tree.js View on Github external
nearestNeighbors(k, query) {
    const neighbors = new Heap(COMPARATOR),
          queue = [this.root];

    let tau = Infinity;

    while (queue.length > 0) {
      const node = queue.pop();

      const d = this.distance(query, node.vantage);

      if (d < tau) {
        neighbors.push({distance: d, item: node.vantage});

        // Trimming
        if (neighbors.size > k)
          neighbors.pop();

mnemonist

Curated collection of data structures for the JavaScript/TypeScript.

MIT
Latest version published 11 months ago

Package Health Score

76 / 100
Full package analysis