src/stdlib/table.c
/*======================================
 * insert_table_ptr -- Insert key & pointer value into table
 *====================================*/
- Insert key & pointer value into table
- Insert key & pointer value into table
void
insert_table_ptr (TABLE tab, CNSTRING key, VPTR ptr)
{
	INT * oldval = 0;
	ASSERT(tab);
	ASSERT(tab->vtable == &vtable_for_table);
	if (tab->rbtree) {
		RBNODE node = RbExactQuery(tab->rbtree, key);
		if (node) {
			VPTR oldptr = RbGetInfo(node);
			if (oldptr != ptr) {
				RbSetInfo(node, ptr);
				rbdestroy_value(tab, oldptr);
			}
			return;
		}
		RbTreeInsert(tab->rbtree, strsave(key), ptr);
	} else {
		oldval = insert_hashtab(tab->hashtab, key, ptr);
		if (oldval && tab->destroyfunc) {
			(*tab->destroyfunc)(oldval);
		}
	}
}
void insert_table_ptr ( TABLE tab , CNSTRING key , VPTR ptr ) { INT * oldval = 0 ; ASSERT ( tab ) ; ASSERT ( tab -> vtable == & vtable_for_table ) ; if ( tab -> rbtree ) { RBNODE node = RbExactQuery ( tab -> rbtree , key ) ; if ( node ) { VPTR oldptr = RbGetInfo ( node ) ; if ( oldptr != ptr ) { RbSetInfo ( node , ptr ) ; rbdestroy_value ( tab , oldptr ) ; } return ; } RbTreeInsert ( tab -> rbtree , strsave ( key ) , ptr ) ; } else { oldval = insert_hashtab ( tab -> hashtab , key , ptr ) ; if ( oldval && tab -> destroyfunc ) { ( * tab -> destroyfunc ) ( oldval ) ; } } }
insert_table_ptr -- Insert key & pointer value into table
insert_table_ptr -- Insert key & pointer value into table
/* first see if key already exists, so we can just change value */