예제 #1
0
void *BSTree_get(BSTree *map, void *key) {
    if (map->root == NULL) {
        return NULL;
    } else {
        BSTreeNode *node = BSTree_getnode(map, map->root, key);
        return node == NULL ? NULL : node->data;
    }
}
예제 #2
0
파일: bstree.c 프로젝트: HanLuo/snippets
void* BSTree_get(BSTree* map, void* key) {
    if(map->root == 0) {
        return 0;
    }
    else {
        BSTreeNode* node = BSTree_getnode(map, map->root, key);
        return node ? node->value : 0;
    }
}
예제 #3
0
파일: bstree.c 프로젝트: HanLuo/snippets
static BSTreeNode* BSTree_getnode(BSTree* map, BSTreeNode* node, void* key) {
    int cmp = map->compare(node->key, key);

    if(cmp == 0) {
        return node;
    }
    else if(cmp < 0) {
        if(node->left)
            return BSTree_getnode(map, node->left, key);
        else
            return 0;
    }
    else {
        if(node->right)
            return BSTree_getnode(map, node->right, key);
        else
            return 0;
    }
}
예제 #4
0
파일: bstree.c 프로젝트: shackijj/lcthw
static inline BSTreeNode *BSTree_getnode(BSTree *map, BSTreeNode *node, void *key, uint32_t hash)
{
    //int cmp = map->compare(node->key, key);

    if(node->hash == hash && map->compare(node->key, key) == 0) {
        return node;
    } else if (node->hash < hash) {
        if(node->left) {
            return BSTree_getnode(map, node->left, key, hash);
        } else {
            return NULL;
        }
    } else {
        if(node->right) {
            return BSTree_getnode(map, node->right, key, hash);
        } else {
            return NULL;
        }
    }
    
    return NULL;
}
예제 #5
0
파일: bstree.c 프로젝트: shackijj/lcthw
void *BSTree_get(BSTree *map, void *key)
{
    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) {
        return NULL;
    } else {
        BSTreeNode *node = BSTree_getnode(map, map->root, key, hash);
        return node == NULL ? NULL : node->data;
    }
error:
    return NULL;
}