Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaScript fast lookup data structure?

Tags:

javascript

I have an array of 109582 strings ordered alphabetically. My web application will be making a lot of rapid checks for whether a given string is contained in the array. Obviously I could make a wrapper class that is a hash table or binary tree, but is there any native JavaScript data structure that I can use instead?

like image 245
user3609145 Avatar asked May 06 '14 16:05

user3609145


People also ask

Which data structure is used for fast lookup?

A heap will only let you search quickly for the minimum element (find it in O(1) time, remove it in O(log n) time). If you design it the other way, it will let you find the maximum, but you don't get both. To search for arbitrary elements quickly (in O(log n) time), you'll want the binary search tree. Good answer.

Which data structure is best for lookup?

What is the most efficient data structure for this? Looking at complexity analysis, Hashtables seem to be the most efficient for lookups.

What data structure does JavaScript use?

JavaScript has primitive (built in) and non-primitive (not built in) data structures. Primitive data structures come by default with the programming language and you can implement them out of the box (like arrays and objects).

What is lookup in data structure?

In computer science, a lookup table is a data structure, usually an array or associative array, often used to replace a runtime computation with a simpler array indexing operation.


1 Answers

Sure. Make an dictionary object

dict = {
  string1: 1,
  string2: 1,
etc

It's guaranteed to provide O(1) lookup time.

like image 164
gog Avatar answered Sep 30 '22 20:09

gog