Note that there are some explanatory texts on larger screens.

plurals
  1. POAn efficient Javascript set structure
    primarykey
    data
    text
    <p>After reading many similar questions:</p> <ul> <li><a href="https://stackoverflow.com/questions/2523436/javascript-implementation-of-a-set-data-structure">JavaScript implementation of a set data structure</a></li> <li><a href="https://stackoverflow.com/questions/7958292/mimicking-sets-in-javascript">Mimicking sets in JavaScript?</a></li> <li><a href="https://stackoverflow.com/questions/12204472/node-js-traditional-data-structures-such-as-set-etc-anything-like-java-uti">Node JS, traditional data structures? (such as Set, etc), anything like Java.util for node?</a></li> <li><a href="https://stackoverflow.com/questions/15555656/efficient-javascript-array-lookup">Efficient Javascript Array Lookup</a></li> <li><a href="https://stackoverflow.com/questions/143847/best-way-to-find-an-item-in-a-javascript-array">Best way to find if an item is in a JavaScript array?</a></li> <li><a href="https://stackoverflow.com/questions/237104/array-containsobj-in-javascript">How do I check if an array includes an object in JavaScript?</a></li> </ul> <p>I still have a question: suppose I have a large array of strings (several thousands), and I have to make many lookups (i.e. check many times whether a given string is contained in this array). What is the most <em>efficient</em> way to do this in Node.js ?</p> <p>A. Sort the array of strings, then use binary search? or:</p> <p>B. Convert the strings to keys of an object, then use the "in" operator</p> <p>?</p> <p>I know that the complexity of A is O(log N), where N is the number of strings.</p> <p>But I don't know the complexity of B.</p> <p>IF a Javascript object is implemented as a hash table, then the complexity of B is, on average, O(1), which is better than A. However, I don't know if a Javascript object is really implemented as a hash table!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload