Changeset View
Changeset View
Standalone View
Standalone View
src/radix.h
Show First 20 Lines • Show All 249 Lines • ▼ Show 20 Lines | public: | ||||
} | } | ||||
}; | }; | ||||
struct RadixNode : public boost::noncopyable { | struct RadixNode : public boost::noncopyable { | ||||
IMPLEMENT_RCU_REFCOUNT(uint64_t); | IMPLEMENT_RCU_REFCOUNT(uint64_t); | ||||
private: | private: | ||||
union { | union { | ||||
std::array<std::atomic<RadixElement>, CHILD_PER_LEVEL> childs; | std::array<std::atomic<RadixElement>, CHILD_PER_LEVEL> children; | ||||
std::array<RadixElement, CHILD_PER_LEVEL> | std::array<RadixElement, CHILD_PER_LEVEL> | ||||
non_atomic_childs_DO_NOT_USE; | non_atomic_children_DO_NOT_USE; | ||||
}; | }; | ||||
public: | public: | ||||
RadixNode(uint32_t level, const K &key, RadixElement e) | RadixNode(uint32_t level, const K &key, RadixElement e) | ||||
: non_atomic_childs_DO_NOT_USE() { | : non_atomic_children_DO_NOT_USE() { | ||||
get(level, key)->store(e); | get(level, key)->store(e); | ||||
} | } | ||||
~RadixNode() { | ~RadixNode() { | ||||
for (RadixElement e : non_atomic_childs_DO_NOT_USE) { | for (RadixElement e : non_atomic_children_DO_NOT_USE) { | ||||
e.release(); | e.release(); | ||||
} | } | ||||
} | } | ||||
std::atomic<RadixElement> *get(uint32_t level, const K &key) { | std::atomic<RadixElement> *get(uint32_t level, const K &key) { | ||||
return &childs[(key >> (level * BITS)) & MASK]; | return &children[(key >> (level * BITS)) & MASK]; | ||||
} | } | ||||
}; | }; | ||||
// Make sure the alignment works for T and RadixElement. | // Make sure the alignment works for T and RadixElement. | ||||
static_assert(alignof(T) > 1, "T's alignment must be 2 or more."); | static_assert(alignof(T) > 1, "T's alignment must be 2 or more."); | ||||
static_assert(alignof(RadixNode) > 1, | static_assert(alignof(RadixNode) > 1, | ||||
"RadixNode alignment must be 2 or more."); | "RadixNode alignment must be 2 or more."); | ||||
}; | }; | ||||
#endif // BITCOIN_RADIX_H | #endif // BITCOIN_RADIX_H |