Guest User

Untitled

a guest
Jun 23rd, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. ///a c++ std::map
  2. public struct std_map(K, V) {
  3. private map_node!(K, V)* head;
  4. public size_t size;
  5.  
  6. public alias values this;
  7. public @property V[K] values() {
  8. if (!head)
  9. return null;
  10. V[K] result;
  11. walkTree(result, head);
  12. return result;
  13. }
  14.  
  15. private void walkTree(ref V[K] result, map_node!(K, V)* node) {
  16. if (node.isNull)
  17. walkTree(result, node.parent);
  18. else
  19. result[node.pair.t1] = node.pair.t2;
  20.  
  21. if (!node.left.isNull)
  22. walkTree(result, node.left);
  23.  
  24. if (!node.right.isNull)
  25. walkTree(result, node.right);
  26. }
  27. }
  28.  
  29. private struct map_node(K, V) {
  30. map_node* left;
  31. map_node* parent;
  32. map_node* right;
  33. ubyte isBlack;
  34. ubyte isNull;
  35. std_pair!(K,V) pair;
  36. }
  37.  
  38. private struct std_pair(T1, T2) {
  39. T1 t1;
  40. T2 t2;
  41. }
Add Comment
Please, Sign In to add comment