Пример #1
0
static struct ddb_entry *pack_hash(struct ddb_packed *pack,
                                   struct ddb_map *keys_map)
{
    char *hash = NULL;
    struct ddb_entry *order = NULL;
    struct ddb_map_cursor *c = NULL;
    struct ddb_entry key;
    uint32_t i = 0;
    int err = -1;

    if (!(order = malloc(pack->head->num_keys * sizeof(struct ddb_entry))))
        goto end;

    if (pack->head->num_keys > DDB_HASH_MIN_KEYS){
        uint32_t hash_size = 0;
        if (!(hash = ddb_build_cmph(keys_map, &hash_size)))
            goto end;
        buffer_new_section(pack, 0);
        if (buffer_write_data(pack, hash, hash_size))
            goto end;
        SETFLAG(pack->head, F_HASH);
    }

    if (!(c = ddb_map_cursor_new(keys_map)))
        goto end;
    while (ddb_map_next_str(c, &key)){
        if (hash)
            i = cmph_search_packed(hash, key.data, key.length);
        order[i++] = key;
    }
    err = 0;
end:
    ddb_map_cursor_free(c);
    free(hash);
    if (err){
        free(order);
        return NULL;
    }
    return order;
}
Пример #2
0
static inline cmph_uint32 _chd_search(void * packed_chd_phf, void * packed_cr, const char *key, cmph_uint32 keylen)
{
	register cmph_uint32 bin_idx = cmph_search_packed(packed_chd_phf, key, keylen);
	register cmph_uint32 rank = compressed_rank_query_packed(packed_cr, bin_idx);
	return bin_idx - rank;
}