void register_node_class(node_class_t *nc) { cmsg_bytes_t key = cmsg_cstring_bytes(nc->name); if (hashtable_contains(&node_class_table, key)) { die("Duplicate node class name %s\n", nc->name); } hashtable_put(&node_class_table, key, nc); }
bool mapping_contains(const node *mapping, uint8_t *scalar, size_t length) { PRECOND_NONNULL_ELSE_FALSE(mapping, scalar); PRECOND_ELSE_FALSE(MAPPING == node_kind(mapping), 0 < length); node *key = make_scalar_node(scalar, length, SCALAR_STRING); bool result = hashtable_contains(mapping->content.mapping, key); node_free(key); return result; }
int bind_node(cmsg_bytes_t name, node_t *n) { if (name.len == 0) { warn("Binding to empty name forbidden\n"); return 0; } if (hashtable_contains(&directory, name)) { return 0; } hashtable_put(&directory, name, n); hashtable_put(&n->names, name, NULL); info("Binding node <<%.*s>> of class %s\n", name.len, name.bytes, n->node_class->name); announce_binding(name, 1); return 1; }
boolean hashtable_add(hashtable_t* hashtable, void* key, void* item) { if (hashtable_contains(hashtable, key)) return false; uint hash = hashtable->hash(key, hashtable->key_size); if (_inner_hashtable_add(hashtable->items, hashtable->keys, hashtable->capacity, hash, hashtable->key_size, key, item)) { hashtable->count++; return true; } return false; }