Commit 147d909f authored by butataatawa's avatar butataatawa Committed by Jesse Beder
Browse files

Fix inconsistent Node::size when removing a key with unassigned node (#327) (#449)

parent e3492bb3
...@@ -132,6 +132,14 @@ inline bool node_data::remove(const Key& key, shared_memory_holder pMemory) { ...@@ -132,6 +132,14 @@ inline bool node_data::remove(const Key& key, shared_memory_holder pMemory) {
if (m_type != NodeType::Map) if (m_type != NodeType::Map)
return false; return false;
kv_pairs::iterator it = m_undefinedPairs.begin();
while (it != m_undefinedPairs.end()) {
kv_pairs::iterator jt = std::next(it);
if (it->first->equals(key, pMemory))
m_undefinedPairs.erase(it);
it = jt;
}
for (node_map::iterator it = m_map.begin(); it != m_map.end(); ++it) { for (node_map::iterator it = m_map.begin(); it != m_map.end(); ++it) {
if (it->first->equals(key, pMemory)) { if (it->first->equals(key, pMemory)) {
m_map.erase(it); m_map.erase(it);
......
...@@ -88,6 +88,13 @@ TEST(NodeTest, MapWithUndefinedValues) { ...@@ -88,6 +88,13 @@ TEST(NodeTest, MapWithUndefinedValues) {
EXPECT_EQ(2, node.size()); EXPECT_EQ(2, node.size());
} }
TEST(NodeTest, RemoveUnassignedNode) {
Node node(NodeType::Map);
node["key"];
node.remove("key");
EXPECT_EQ(node.size(), 0);
}
TEST(NodeTest, MapForceInsert) { TEST(NodeTest, MapForceInsert) {
Node node; Node node;
Node k1("k1"); Node k1("k1");
......
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