susumu.yata
null+****@clear*****
Tue Aug 20 15:25:42 JST 2013
susumu.yata 2013-08-20 15:25:42 +0900 (Tue, 20 Aug 2013) New Revision: b994f680ffbb185202e23f4cec9a11f6f6e8b80d https://github.com/groonga/grnxx/commit/b994f680ffbb185202e23f4cec9a11f6f6e8b80d Message: Rename constant variables. Modified files: lib/grnxx/map/double_array.cpp Modified: lib/grnxx/map/double_array.cpp (+42 -42) =================================================================== --- lib/grnxx/map/double_array.cpp 2013-08-19 18:28:21 +0900 (4e6824d) +++ lib/grnxx/map/double_array.cpp 2013-08-20 15:25:42 +0900 (c333292) @@ -43,10 +43,10 @@ constexpr uint64_t BLOCK_INVALID_ID = (1ULL << 40) - 1; constexpr uint64_t BLOCK_SIZE = 1ULL << 9; constexpr uint64_t BLOCK_MAX_COUNT = 16; -constexpr uint64_t NODE_TERMINAL_LABEL = 0x100; -constexpr uint64_t NODE_MAX_LABEL = NODE_TERMINAL_LABEL; -constexpr uint64_t NODE_INVALID_LABEL = NODE_MAX_LABEL + 1; -constexpr uint64_t NODE_INVALID_OFFSET = 0; +constexpr uint64_t TERMINAL_LABEL = 0x100; +constexpr uint64_t MAX_LABEL = TERMINAL_LABEL; +constexpr uint64_t INVALID_LABEL = MAX_LABEL + 1; +constexpr uint64_t INVALID_OFFSET = 0; constexpr uint64_t ROOT_NODE_ID = 0; @@ -262,9 +262,9 @@ class Node { void unset_is_phantom() { value_ = (value_ & IS_ORIGIN_FLAG) | - (NODE_INVALID_LABEL << LABEL_SHIFT) | - (NODE_INVALID_LABEL << CHILD_SHIFT) | - (NODE_INVALID_OFFSET << OFFSET_SHIFT); + (INVALID_LABEL << LABEL_SHIFT) | + (INVALID_LABEL << CHILD_SHIFT) | + (INVALID_OFFSET << OFFSET_SHIFT); } void set_is_origin(bool is_origin) { if (is_origin) { @@ -313,7 +313,7 @@ class Node { value_ = (value_ & ~(IS_LEAF_FLAG | (OFFSET_MASK << OFFSET_SHIFT) | (CHILD_MASK << CHILD_SHIFT))) | (offset << OFFSET_SHIFT) | - (NODE_INVALID_LABEL << CHILD_SHIFT); + (INVALID_LABEL << CHILD_SHIFT); } else { value_ = (value_ & ~(OFFSET_MASK << OFFSET_SHIFT)) | (offset << OFFSET_SHIFT); @@ -520,11 +520,11 @@ bool DoubleArrayImpl::find(KeyArg key, int64_t *key_id) { } } if (!node.is_leaf()) { - if (node.child() != NODE_TERMINAL_LABEL) { + if (node.child() != TERMINAL_LABEL) { // Not found. return false; } - node_id = node.offset() ^ NODE_TERMINAL_LABEL; + node_id = node.offset() ^ TERMINAL_LABEL; node = nodes_->get(node_id); if (!node.is_leaf()) { // Not found. @@ -581,7 +581,7 @@ bool DoubleArrayImpl::remove(KeyArg key) { return false; } pool_->unset(node->key_id()); - node->set_offset(NODE_INVALID_OFFSET); + node->set_offset(INVALID_OFFSET); return true; } @@ -628,8 +628,8 @@ bool DoubleArrayImpl::find_longest_prefix_match(KeyArg query, return found; } - if (node.child() == NODE_TERMINAL_LABEL) { - Node leaf_node = nodes_->get(node.offset() ^ NODE_TERMINAL_LABEL); + if (node.child() == TERMINAL_LABEL) { + Node leaf_node = nodes_->get(node.offset() ^ TERMINAL_LABEL); if (leaf_node.is_leaf()) { if (pool_->get(leaf_node.key_id(), key)) { if (key_id) { @@ -660,8 +660,8 @@ bool DoubleArrayImpl::find_longest_prefix_match(KeyArg query, found = true; } } - } else if (node.child() == NODE_TERMINAL_LABEL) { - node = nodes_->get(node.offset() ^ NODE_TERMINAL_LABEL); + } else if (node.child() == TERMINAL_LABEL) { + node = nodes_->get(node.offset() ^ TERMINAL_LABEL); if (pool_->get(node.key_id(), key)) { if (key_id) { *key_id = node.key_id(); @@ -690,7 +690,7 @@ void DoubleArrayImpl::create_impl(Storage *storage, uint32_t storage_node_id) { header_->siblings_storage_node_id = siblings_->storage_node_id(); header_->blocks_storage_node_id = blocks_->storage_node_id(); Node * const root_node = reserve_node(ROOT_NODE_ID); - root_node[NODE_INVALID_OFFSET - ROOT_NODE_ID].set_is_origin(true); + root_node[INVALID_OFFSET - ROOT_NODE_ID].set_is_origin(true); } catch (...) { storage->unlink_node(storage_node_id_); throw; @@ -742,7 +742,7 @@ bool DoubleArrayImpl::replace_key(int64_t key_id, KeyArg src_key, } pool_->reset(key_id, dest_key); dest_node->set_key_id(key_id); - src_node->set_offset(NODE_INVALID_OFFSET); + src_node->set_offset(INVALID_OFFSET); return true; } @@ -758,19 +758,19 @@ void DoubleArrayImpl::defrag(DoubleArrayImpl *src_impl, uint64_t src_node_id, const uint64_t src_offset = src_node.offset(); uint64_t dest_offset; { - uint64_t labels[NODE_MAX_LABEL + 1]; + uint64_t labels[MAX_LABEL + 1]; uint64_t num_labels = 0; uint64_t label = src_node.child(); - while (label != NODE_INVALID_LABEL) { + while (label != INVALID_LABEL) { const uint64_t child_node_id = src_offset ^ label; const Node child_node = src_impl->nodes_->get(child_node_id); - if (child_node.is_leaf() || (child_node.child() != NODE_INVALID_LABEL)) { + if (child_node.is_leaf() || (child_node.child() != INVALID_LABEL)) { labels[num_labels++] = label; } if (child_node.has_sibling()) { label = src_impl->siblings_->get(child_node_id); } else { - label = NODE_INVALID_LABEL; + label = INVALID_LABEL; } } if (num_labels == 0) { @@ -795,12 +795,12 @@ void DoubleArrayImpl::defrag(DoubleArrayImpl *src_impl, uint64_t src_node_id, } uint16_t label = dest_node.child(); - while (label != NODE_INVALID_LABEL) { + while (label != INVALID_LABEL) { const uint64_t next_src_node_id = src_offset ^ label; const uint64_t next_dest_node_id = dest_offset ^ label; defrag(src_impl, next_src_node_id, next_dest_node_id); label = nodes_->get_value(next_dest_node_id).has_sibling() ? - siblings_->get(next_dest_node_id) : NODE_INVALID_LABEL; + siblings_->get(next_dest_node_id) : INVALID_LABEL; } } @@ -831,11 +831,11 @@ bool DoubleArrayImpl::find_leaf(KeyArg key, Node **leaf_node, // Found. return true; } - if (node->child() != NODE_TERMINAL_LABEL) { + if (node->child() != TERMINAL_LABEL) { // Not found. return false; } - const uint64_t node_id = node->offset() ^ NODE_TERMINAL_LABEL; + const uint64_t node_id = node->offset() ^ TERMINAL_LABEL; node = &nodes_->get_value(node_id); *leaf_node = node; return node->is_leaf(); @@ -865,16 +865,16 @@ bool DoubleArrayImpl::insert_leaf(KeyArg key, Node *node, } uint64_t labels[2]; labels[0] = (key_pos < stored_key.size()) ? - stored_key[key_pos] : NODE_TERMINAL_LABEL; - labels[1] = (key_pos < key.size()) ? key[key_pos] : NODE_TERMINAL_LABEL; + stored_key[key_pos] : TERMINAL_LABEL; + labels[1] = (key_pos < key.size()) ? key[key_pos] : TERMINAL_LABEL; *leaf_node = separate(node, labels); return true; - } else if (node->label() == NODE_TERMINAL_LABEL) { + } else if (node->label() == TERMINAL_LABEL) { *leaf_node = node; return true; } else { const uint64_t label = (key_pos < key.size()) ? - key[key_pos] : NODE_TERMINAL_LABEL; + key[key_pos] : TERMINAL_LABEL; resolve(node, label); *leaf_node = insert_node(node, label); return true; @@ -883,7 +883,7 @@ bool DoubleArrayImpl::insert_leaf(KeyArg key, Node *node, Node *DoubleArrayImpl::insert_node(Node *node, uint64_t label) { uint64_t offset = node->offset(); - if (node->is_leaf() || (offset == NODE_INVALID_OFFSET)) { + if (node->is_leaf() || (offset == INVALID_OFFSET)) { offset = find_offset(&label, 1); } const uint64_t next_node_id = offset ^ label; @@ -893,15 +893,15 @@ Node *DoubleArrayImpl::insert_node(Node *node, uint64_t label) { if (node->is_leaf()) { next_node[offset - next_node_id].set_is_origin(true); next_node->set_key_id(node->key_id()); - } else if (node->offset() == NODE_INVALID_OFFSET) { + } else if (node->offset() == INVALID_OFFSET) { next_node[offset - next_node_id].set_is_origin(true); } node->set_offset(offset); const uint64_t child_label = node->child(); - if (child_label == NODE_INVALID_LABEL) { + if (child_label == INVALID_LABEL) { node->set_child(label); - } else if ((label == NODE_TERMINAL_LABEL) || - ((child_label != NODE_TERMINAL_LABEL) && (label < child_label))) { + } else if ((label == TERMINAL_LABEL) || + ((child_label != TERMINAL_LABEL) && (label < child_label))) { // The child node becomes the first child. *next_sibling = child_label; next_node->set_has_sibling(); @@ -911,13 +911,13 @@ Node *DoubleArrayImpl::insert_node(Node *node, uint64_t label) { Node *prev_node = &next_node[prev_node_id - next_node_id]; uint8_t *prev_sibling = &next_sibling[prev_node_id - next_node_id]; uint64_t sibling_label = prev_node->has_sibling() ? - *prev_sibling : NODE_INVALID_LABEL; + *prev_sibling : INVALID_LABEL; while (label > sibling_label) { prev_node_id = offset ^ sibling_label; prev_node = &next_node[prev_node_id - next_node_id]; prev_sibling = &next_sibling[prev_node_id - next_node_id]; sibling_label = prev_node->has_sibling() ? - *prev_sibling : NODE_INVALID_LABEL; + *prev_sibling : INVALID_LABEL; } *next_sibling = *prev_sibling; *prev_sibling = label; @@ -942,8 +942,8 @@ Node *DoubleArrayImpl::separate(Node *node, uint64_t labels[2]) { nodes[1]->set_label(labels[1]); nodes[0][offset - node_ids[0]].set_is_origin(true); node->set_offset(offset); - if ((labels[0] == NODE_TERMINAL_LABEL) || - ((labels[1] != NODE_TERMINAL_LABEL) && (labels[0] < labels[1]))) { + if ((labels[0] == TERMINAL_LABEL) || + ((labels[1] != TERMINAL_LABEL) && (labels[0] < labels[1]))) { sibling_block[node_ids[0] % BLOCK_SIZE] = static_cast<uint8_t>(labels[1]); nodes[0]->set_has_sibling(); node->set_child(labels[0]); @@ -957,7 +957,7 @@ Node *DoubleArrayImpl::separate(Node *node, uint64_t labels[2]) { void DoubleArrayImpl::resolve(Node *node, uint64_t label) { uint64_t offset = node->offset(); - if (offset == NODE_INVALID_OFFSET) { + if (offset == INVALID_OFFSET) { return; } uint64_t dest_node_id = offset ^ label; @@ -968,16 +968,16 @@ void DoubleArrayImpl::resolve(Node *node, uint64_t label) { Node * const node_block = dest_node - (dest_node_id % BLOCK_SIZE); uint8_t * const sibling_block = &siblings_->get_value(dest_node_id & ~(BLOCK_SIZE - 1)); - uint64_t labels[NODE_MAX_LABEL + 1]; + uint64_t labels[MAX_LABEL + 1]; uint64_t num_labels = 0; uint64_t child_label = node->child(); - while (child_label != NODE_INVALID_LABEL) { + while (child_label != INVALID_LABEL) { labels[num_labels++] = child_label; const uint64_t child_node_id = offset ^ child_label; if (node_block[child_node_id % BLOCK_SIZE].has_sibling()) { child_label = sibling_block[child_node_id % BLOCK_SIZE]; } else { - child_label = NODE_INVALID_LABEL; + child_label = INVALID_LABEL; } } labels[num_labels] = label; -------------- next part -------------- HTML����������������������������... Download