On Fri, Dec 27, 2013 at 10:29 AM, Lonnie Olson <[email protected]> wrote:
> Or just use some other binary indexing method.  MySQL, Postgres, SQLite, BDB.

Proof of concept in SQLite.

# Generate hashes
for word in $(cat /usr/share/dict/words); do echo -en "$word\t"; echo
"$word" | sha256sum; done > words
# Create basic Database schema
sqlite3 words.db
CREATE TABLE hashes (id INTEGER PRIMARY KEY, hash TEXT, value TEXT);
.quit
# Insert hashes into database
awk '{print "INSERT INTO hashes (hash,value) VALUES (\"" $2 "\",\"" $1
"\");"}' words | sqlite3 words.db
# Create an index on the hash column
sqlite3 words.db
CREATE UNIQUE INDEX hash on hashes (hash);
.quit
# Query database for hash values
awk '{print "SELECT value FROM hashes WHERE hash=\"" $2 "\";"}' words
| sqlite3 words.db
# OR use an insert, and check return value for success
echo "INSERT INTO hashes (hash,value) VALUES
('f2ca1bb6c7e907d06dafe4687e579fce76b37e4e93b7605022da52e6ccc26fd2','test');"
| sqlite3 words.db || echo "COLLISION FOUND"

/*
PLUG: http://plug.org, #utah on irc.freenode.net
Unsubscribe: http://plug.org/mailman/options/plug
Don't fear the penguin.
*/

Reply via email to