Navigation Menu

Skip to content

Commit

Permalink
Merge pull request #763 from groonga/dat-limit-num-nodes-per-key
Browse files Browse the repository at this point in the history
dat: limit the number of nodes per key

Patch by Susumu Yata. Thanks!!!
  • Loading branch information
kou committed Sep 30, 2017
2 parents f459ad7 + 50e24c8 commit 15ee139
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/dat/dat.hpp
Expand Up @@ -126,6 +126,7 @@ const UInt64 MIN_FILE_SIZE = 1 << 16;
const UInt64 DEFAULT_FILE_SIZE = 1 << 20;
const UInt64 MAX_FILE_SIZE = (UInt64)1 << 40;
const double DEFAULT_NUM_NODES_PER_KEY = 4.0;
const double MAX_NUM_NODES_PER_KEY = 16.0;
const double DEFAULT_AVERAGE_KEY_LENGTH = 16.0;
const UInt32 MAX_KEY_BUF_SIZE = 0x80000000U;
const UInt32 MAX_TOTAL_KEY_LENGTH = 0xFFFFFFFFU;
Expand Down
8 changes: 8 additions & 0 deletions lib/dat/trie.cpp
Expand Up @@ -67,7 +67,11 @@ void Trie::create(const char *file_name,
if (num_nodes_per_key < 1.0) {
num_nodes_per_key = DEFAULT_NUM_NODES_PER_KEY;
}
if (num_nodes_per_key > MAX_NUM_NODES_PER_KEY) {
num_nodes_per_key = MAX_NUM_NODES_PER_KEY;
}
GRN_DAT_THROW_IF(PARAM_ERROR, num_nodes_per_key < 1.0);
GRN_DAT_THROW_IF(PARAM_ERROR, num_nodes_per_key > MAX_NUM_NODES_PER_KEY);

if (average_key_length < 1.0) {
average_key_length = DEFAULT_AVERAGE_KEY_LENGTH;
Expand Down Expand Up @@ -105,9 +109,13 @@ void Trie::create(const Trie &trie,
num_nodes_per_key = DEFAULT_NUM_NODES_PER_KEY;
} else {
num_nodes_per_key = 1.0 * trie.num_nodes() / trie.num_keys();
if (num_nodes_per_key > MAX_NUM_NODES_PER_KEY) {
num_nodes_per_key = MAX_NUM_NODES_PER_KEY;
}
}
}
GRN_DAT_THROW_IF(PARAM_ERROR, num_nodes_per_key < 1.0);
GRN_DAT_THROW_IF(PARAM_ERROR, num_nodes_per_key > MAX_NUM_NODES_PER_KEY);

if (average_key_length < 1.0) {
if (trie.num_keys() == 0) {
Expand Down

0 comments on commit 15ee139

Please sign in to comment.