Skip to content

Instantly share code, notes, and snippets.

@mikolalysenko
Created July 10, 2013 15:47
Show Gist options
  • Save mikolalysenko/5967444 to your computer and use it in GitHub Desktop.
Save mikolalysenko/5967444 to your computer and use it in GitHub Desktop.
//Initialize array
var array = new Array(1024)
for(var i=0; i<array.length; ++i) {
array[i] = []
}
//Indexing...
function get(key) {
var list = array[key % array.length]
for(var i=0; i<list.length; ++i) {
if(list[i].key === key) {
return list[i].value
}
}
return undefined
}
function set(key, value) {
var list = array[key % array.length]
for(var i=0; i<list.length; ++i) {
if(list[i].key === key) {
return list[i].value = value
}
}
list.push({key: key, value: value})
return value
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment