1 #include <BindingTable.h>
5 BindingTable *BindingTable_create() {
6 BindingTable *this = (BindingTable*) malloc( sizeof( BindingTable ) );
7 (*this) = (HashVector) {
9 .variant = Nibble_index_levels, .size = 16, .entries = 0
10 }, .fill = 0, .holes = 0, .type = &Bindingitem
15 void BindingTable_release(BindingTable *bt) {
17 Vector_resize( &bt->table, 0, Vector_free_any, 0 );
22 void BindingTable_set(BindingTable *bt,char *name,void *value) {
23 Binding *b = (Binding*) HashVector_find( bt, name );
25 b = (Binding*) malloc( sizeof( Binding ) );
27 HashVector_add( bt, b );
32 void *BindingTable_get(BindingTable *bt,char *name) {
33 Binding *b = (Binding*) HashVector_find( bt, name );
34 return b? b->value : 0;
37 void BindingTable_deref(BindingTable *bt,Tuple *t) {
39 for ( i = 0; i < t->size; i++ ) {
40 if ( t->elements[i] ) {
41 t->elements[i] = BindingTable_get( bt, t->elements[i] );
47 int BindingTable_unify(
48 BindingTable *bt,char *n1,char *n2,int (*eq)(void*,void*)) {
49 void *v1 = BindingTable_get( bt, n1 );
50 void *v2 = BindingTable_get( bt, n2 );
51 if ( v2 && v1 == 0 ) {
52 BindingTable_set( bt, n1, v2 );
54 if ( v1 && v2 == 0 ) {
55 BindingTable_set( bt, n2, v1 );
57 return ( v1 && v2 )? ( eq? ( eq( v1, v2 ) == 0 ) : ( v1 == v2 ) ) : 1;
61 Tuple *BindingTable_get_all(BindingTable *bt,Tuple *t) {
62 Tuple *vt = Tuple_clone( t );
63 BindingTable_deref( bt, vt );
67 void BindingTable_set_all(BindingTable *bt,Tuple *nm,Tuple *vs,int all) {
69 for ( i = 0; i < nm->size; i++ ) {
70 BindingTable_set( bt, nm->elements[i], vs->elements[i] );