HEADER_DECLARE hash_t hash_rec(Term* term, hash_t hash){ term = chase(term); switch(term->type){ case INTEGER: return hash_integer(term->data.integer, hash); case FUNCTOR: hash = hash_atom(term->data.functor.atom, hash); functor_size_t size = term->data.functor.size; if(size){ hash = hash_byte(size, hash); for(functor_size_t i = 0; i < size; i++){ hash = hash_rec(term->data.functor.args[i], hash); } } return hash; case STRING: return hash_string(&term->data.string, hash); case VAR: fatal_error("Cannot hash variable '%s'", term->data.var.name); case DICT: fatal_error("unimplemented: hash dict"); case MOVED: fatal_error("Cannot hash a moved term"); } UNREACHABLE; }
void *key_integer_get(dword *ary,dword key) { if(!*ary)return 0; array *m = (array *)*ary; dword tmp = hash_integer(key)%buffer; while(m[tmp].key) { if(key==m[tmp].key)break; ++tmp; } return (void *)m[tmp].value; }
array *key_integer_set(dword *ary,dword key,void *data) { if(!*ary) { //(dword)m[0].value = (dword)buffer; *ary = (dword)malloc(sizeof(array)*(buffer+1)); } array *m = (array *)*ary; dword tmp = hash_integer(key)%buffer; while(m[tmp].key) { if(key==m[tmp].key)break; ++tmp; } m[tmp].key = (dword)key; m[tmp].value = (dword)data; return m; }
std::size_t operator()(Integer_type const& t) const { return hash_integer(t); }