Skip to content

Instantly share code, notes, and snippets.

@bga
Created October 26, 2010 12:12
Show Gist options
  • Save bga/646798 to your computer and use it in GitHub Desktop.
Save bga/646798 to your computer and use it in GitHub Desktop.
struct HashTable // Open addressing Hash Table with linear probing
{
int entriesCount;
int id;
HashTableEntry entries[0];
};
void HashTable::_set(Const String key, Value& value)
{
// if key is new
id++;
}
void HashTable::_delete(Const String key)
{
// if key is exist
id++;
}
void _patch(void *ip)
{
// calculate offset in hash table
// create new opcodes by template
// and patch code at address ip
// if key not exist return undefined
// else return address of Value
}
.code
// jit code
; ebx - Object address
; var a:int = b.c
_a:
cmp dword ptr [ebx + 8], %id%; compare .id and inlined id
je _directOffset
push %_a address%
push %address of key String%
call _patch
_directOffset:
mov eax, dword ptr [ebx + 12 + %offset%*32 + 4] ; for int
; fld st(0), [ebx + 12 + %offset%*32 + 4] ; for double
; 12 - .entries, 32 - size of HashTableEntry, 4 - .numberIntValue in Value
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment