Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>sorry, but that sound like a REALLY AWFUL APPROACH! doing a whole scan (of a table, list or whatever) if you want to check if something already exists is just... wrong. this is what <a href="http://en.wikipedia.org/wiki/Hash_table" rel="nofollow noreferrer">hashtables</a> are for! your case sounds like a classical database job... if you don't have a database available you can use a local sqlite file which will provide essential functionalities. let me explain the background... a lookup of "foo" in an hashtable basically consumes O(1) time. which means a static amount of time. because your algorithm knows WHERE to look and can see whether its THERE. hashmaps have the the attitude to run into ambiguiti because of the one-way nature of hashing procedures, which really doesnt matter that much because the hashmap delivers some possible matches which can be compared directly (for a reasonable number of elements, like probably the google index <em>laugh</em>) so if you want (for some reason) stay with your text-file approach, consider the following:</p> <ul> <li>sort your file and insert your data at the right place (alphabetically would be the most intuitive approach). then you can jump from position to position and isolate the area where the word should be. there are several algorithms available, just have a google. but keep it takes longer the more data you have. usually your running time will be O(log(n)) where n is the size of the table.</li> </ul> <p>well this is all basically just to guide you on the right track. you can as well shard your data, this would be for example saving every word beginning with a in the file a.txt and so on. or to split the word into characters and create a folder for every character and the last character is the file, then you check if the file exists. those are stupid suggestions, as you will probably run out of inodes on your disk, but it illustrates that you can CHECK for EXISTENCE witout having to do a FULL SCAN.</p> <p>the main thing is that you have to project some search tree into a reasonable structure (like a database system does automatically for you). the folder example was an example of the basic principle.</p> <p>this wikipedia entry might be a good place to start: <a href="http://en.wikipedia.org/wiki/Binary_search_tree" rel="nofollow noreferrer">http://en.wikipedia.org/wiki/Binary_search_tree</a></p>
 

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