Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ///a c++ std::map
- public struct std_map(K, V) {
- private map_node!(K, V)* head;
- public size_t size;
- public alias values this;
- public @property V[K] values() {
- if (!head)
- return null;
- V[K] result;
- walkTree(result, head);
- return result;
- }
- private void walkTree(ref V[K] result, map_node!(K, V)* node) {
- if (node.isNull)
- walkTree(result, node.parent);
- else
- result[node.pair.t1] = node.pair.t2;
- if (!node.left.isNull)
- walkTree(result, node.left);
- if (!node.right.isNull)
- walkTree(result, node.right);
- }
- }
- private struct map_node(K, V) {
- map_node* left;
- map_node* parent;
- map_node* right;
- ubyte isBlack;
- ubyte isNull;
- std_pair!(K,V) pair;
- }
- private struct std_pair(T1, T2) {
- T1 t1;
- T2 t2;
- }
Add Comment
Please, Sign In to add comment