Example #1
0
static inline void BSTree_setnode(BSTree *map, BSTreeNode *node, void *key, void *data)
{
  int cmp = map->compare(node->key, key);

  if(cmp <= 0) {
    if(node->left) {
      BSTree_setnode(map, node->left, key, data);
    } else {
      node->left = BSTreeNode_create(node, key, data);
    }
  } else {
    if(node->right) {
      BSTree_setnode(map, node->right, key, data);
    } else {
      node->right = BSTreeNode_create(node, key, data);
    }
  }
}
Example #2
0
static inline void BSTree_setnode(BSTree *map, BSTreeNode *node, void *key, void *data, uint32_t hash)
{
    //int cmp = map->compare(node->key, key);

    if(node->hash <= hash) {
        if(node->left) {
            BSTree_setnode(map, node->left, key, data, hash);
        } else {
            node->left = BSTreeNode_create(node, key, data, hash);
        }
    } else {
        if(node->right) {
            BSTree_setnode(map, node->right, key, data, hash);
        } else {
            node->right = BSTreeNode_create(node, key, data, hash);
        }
    }
}
Example #3
0
int BSTree_set(BSTree *map, void *key, void *data) {
    if (map->root == NULL) {
        map->root = BSTreeNode_create(NULL, key, data);
        check_mem(map->root);
    } else {
        BSTree_setnode(map, map->root, key, data);
    }
    return 0;
error:
    return -1;
}
Example #4
0
int BSTree_set(BSTree *map, void *key, void *data)
{
    if (map->root == NULL) {
        // first so just make it and get out
        map->root = BSTreeNode_create(NULL, key, data);
        check_mem(map->root);
    } else {
        BSTree_setnode(map, map->root, key, data);
    }
    
    map->count++;

    return 0;
error:
    return -1;
}
Example #5
0
int BSTree_set(BSTree *map, void *key, void *data)
{
    check(map != NULL, "Map can't be NULL.");
    check(key != NULL, "Key can't be NULL.");

    uint32_t hash = map->hash(key);

    if(map->root == NULL) {
        map->root = BSTreeNode_create(NULL, key, data, hash);
        check_mem(map->root);
    } else {
        BSTree_setnode(map, map->root, key, data, hash);
    }

    return 0;

error:
    return -1;
}