Commit 8147eafa authored by Daniel Salzman's avatar Daniel Salzman

hat-trie: merge hattrie_create with hattrie_create_n

parent 01404156
......@@ -25,17 +25,9 @@
typedef struct qp_trie hattrie_t;
typedef struct qp_trie_it hattrie_iter_t;
#define TRIE_BUCKET_SIZE (-1)
inline static hattrie_t* hattrie_create(void)
{
return qp_trie_create(NULL);
}
inline static hattrie_t* hattrie_create_n(unsigned bucket_size, const struct knot_mm *mm)
inline static hattrie_t* hattrie_create(struct knot_mm *mm)
{
UNUSED(bucket_size);
return qp_trie_create(/*const-cast*/(struct knot_mm *)mm);
return qp_trie_create(mm);
}
inline static void hattrie_free(hattrie_t *trie)
......
......@@ -820,7 +820,7 @@ static void upd_changes(
// Prepare zone changes storage if it doesn't exist.
hattrie_t *zones = conf()->io.zones;
if (zones == NULL) {
zones = hattrie_create_n(TRIE_BUCKET_SIZE, conf()->mm);
zones = hattrie_create(conf()->mm);
if (zones == NULL) {
return;
}
......
......@@ -1239,7 +1239,7 @@ int knot_zone_sign_changeset(const zone_contents_t *zone,
.zone_keys = zone_keys,
.dnssec_ctx = dnssec_ctx,
.changeset = out_ch,
.signed_tree = hattrie_create()
.signed_tree = hattrie_create(NULL)
};
if (args.signed_tree == NULL) {
......
......@@ -652,7 +652,7 @@ static int remove_rr(zone_contents_t *z, const knot_rrset_t *rr,
static int recreate_normal_tree(const zone_contents_t *z, zone_contents_t *out)
{
out->nodes = hattrie_create();
out->nodes = hattrie_create(NULL);
if (out->nodes == NULL) {
return KNOT_ENOMEM;
}
......@@ -707,7 +707,7 @@ static int recreate_normal_tree(const zone_contents_t *z, zone_contents_t *out)
static int recreate_nsec3_tree(const zone_contents_t *z, zone_contents_t *out)
{
out->nsec3_nodes = hattrie_create();
out->nsec3_nodes = hattrie_create(NULL);
if (out->nsec3_nodes == NULL) {
return KNOT_ENOMEM;
}
......
......@@ -24,7 +24,7 @@
zone_tree_t* zone_tree_create()
{
return hattrie_create();
return hattrie_create(NULL);
}
size_t zone_tree_count(const zone_tree_t *tree)
......
/* Copyright (C) 2014 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
/* Copyright (C) 2016 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -29,7 +29,8 @@ static int init(knot_db_t **db, knot_mm_t *mm, void *arg)
}
struct knot_db_trie_opts *opts = arg;
hattrie_t *trie = hattrie_create_n(opts->bucket_size, mm);
UNUSED(opts);
hattrie_t *trie = hattrie_create(mm);
if (!trie) {
return KNOT_ENOMEM;
}
......
/* Copyright (C) 2014 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
/* Copyright (C) 2016 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -18,17 +18,14 @@
#include "libknot/db/db.h"
/* Defines */
#define KNOT_DB_TRIE_BUCKET_SIZE 253 /* 1 page per bucket, see hat-trie.h */
/* Native options. */
struct knot_db_trie_opts {
unsigned bucket_size; /*!< Trie bucket size. */
unsigned unused;
};
/* Default options. */
#define KNOT_DB_TRIE_OPTS_INITIALIZER { \
KNOT_DB_TRIE_BUCKET_SIZE \
0 \
}
const knot_db_api_t *knot_db_trie_api(void);
......@@ -29,7 +29,7 @@ int lookup_init(lookup_t *lookup)
memset(lookup, 0, sizeof(*lookup));
mm_ctx_mempool(&lookup->mm, MM_DEFAULT_BLKSIZE);
lookup->trie = hattrie_create_n(TRIE_BUCKET_SIZE, &lookup->mm);
lookup->trie = hattrie_create(&lookup->mm);
if (lookup->trie == NULL) {
mp_delete(lookup->mm.ctx);
return KNOT_ENOMEM;
......
......@@ -197,7 +197,7 @@ typedef size_t yy_size_t;
*/
#define YY_LESS_LINENO(n) \
do { \
yy_size_t yyl;\
int yyl;\
for ( yyl = n; yyl < yyleng; ++yyl )\
if ( yytext[yyl] == '\n' )\
--yylineno;\
......@@ -215,7 +215,7 @@ typedef size_t yy_size_t;
do \
{ \
/* Undo effects of setting up yytext. */ \
yy_size_t yyless_macro_arg = (n); \
int yyless_macro_arg = (n); \
YY_LESS_LINENO(yyless_macro_arg);\
*yy_cp = yyg->yy_hold_char; \
YY_RESTORE_YY_MORE_OFFSET \
......@@ -243,7 +243,7 @@ struct yy_buffer_state
/* Number of characters read into yy_ch_buf, not including EOB
* characters.
*/
yy_size_t yy_n_chars;
int yy_n_chars;
/* Whether we "own" the buffer - i.e., we know we created it,
* and can realloc() it to grow it, and should free() it to
......@@ -930,7 +930,7 @@ struct yyguts_t
size_t yy_buffer_stack_max; /**< capacity of stack. */
YY_BUFFER_STATE * yy_buffer_stack; /**< Stack as an array. */
char yy_hold_char;
yy_size_t yy_n_chars;
int yy_n_chars;
yy_size_t yyleng_r;
char *yy_c_buf_p;
int yy_init;
......@@ -2170,9 +2170,9 @@ static int yy_get_next_buffer (yyscan_t yyscanner)
else
ret_val = EOB_ACT_CONTINUE_SCAN;
if ((yy_size_t) (yyg->yy_n_chars + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) {
if ((int) (yyg->yy_n_chars + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) {
/* Extend the array by 50%, plus the number we really need. */
yy_size_t new_size = yyg->yy_n_chars + number_to_move + (yyg->yy_n_chars >> 1);
int new_size = yyg->yy_n_chars + number_to_move + (yyg->yy_n_chars >> 1);
YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) cf_realloc((void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf,new_size ,yyscanner );
if ( ! YY_CURRENT_BUFFER_LVALUE->yy_ch_buf )
YY_FATAL_ERROR( "out of dynamic memory in yy_get_next_buffer()" );
......@@ -2572,7 +2572,7 @@ static void cf_ensure_buffer_stack (yyscan_t yyscanner)
* scanner will even need a stack. We use 2 instead of 1 to avoid an
* immediate realloc on the next call.
*/
num_to_alloc = 1; // After all that talk, this was set to 1 anyways...
num_to_alloc = 1; /* After all that talk, this was set to 1 anyways... */
yyg->yy_buffer_stack = (struct yy_buffer_state**)cf_alloc
(num_to_alloc * sizeof(struct yy_buffer_state*)
, yyscanner);
......@@ -2710,7 +2710,7 @@ static void yy_fatal_error (yyconst char* msg , yyscan_t yyscanner)
do \
{ \
/* Undo effects of setting up yytext. */ \
yy_size_t yyless_macro_arg = (n); \
int yyless_macro_arg = (n); \
YY_LESS_LINENO(yyless_macro_arg);\
yytext[yyleng] = yyg->yy_hold_char; \
yyg->yy_c_buf_p = yytext + yyless_macro_arg; \
......
......@@ -383,7 +383,7 @@ static void grp_init(void *scanner, const char *name)
hattrie_t **trie = (hattrie_t **)hattrie_get(extra->share->groups,
name, strlen(name));
if (*trie == NULL) {
*trie = hattrie_create();
*trie = hattrie_create(NULL);
}
extra->current_trie = *trie;
}
......
......@@ -327,7 +327,7 @@ static void grp_init(void *scanner, const char *name)
hattrie_t **trie = (hattrie_t **)hattrie_get(extra->share->groups,
name, strlen(name));
if (*trie == NULL) {
*trie = hattrie_create();
*trie = hattrie_create(NULL);
}
extra->current_trie = *trie;
}
......
......@@ -75,12 +75,12 @@ static int convert(const char *file_out, const char *file_in)
share_t share = {
.out = out,
.ifaces = hattrie_create(),
.groups = hattrie_create(),
.remotes = hattrie_create(),
.acl_xfer = hattrie_create(),
.acl_notify = hattrie_create(),
.acl_update = hattrie_create()
.ifaces = hattrie_create(NULL),
.groups = hattrie_create(NULL),
.remotes = hattrie_create(NULL),
.acl_xfer = hattrie_create(NULL),
.acl_notify = hattrie_create(NULL),
.acl_update = hattrie_create(NULL)
};
// Parse the input file multiple times to get some context.
......
......@@ -481,7 +481,7 @@ static int zone_memstats(const knot_dname_t *dname, void *data)
// Init memory estimation context.
zone_estim_t est = {
.node_table = hattrie_create_n(TRIE_BUCKET_SIZE, &mem_ctx),
.node_table = hattrie_create(&mem_ctx),
};
char buff[KNOT_DNAME_TXT_MAXLEN + 1];
......
......@@ -117,7 +117,7 @@ int main(int argc, char *argv[])
/* Create trie */
value_t *val = NULL;
hattrie_t *trie = hattrie_create();
hattrie_t *trie = hattrie_create(NULL);
ok(trie != NULL, "hattrie: create");
/* Insert keys */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment