Mercurial > hg > Members > tatsuki > TreeMap
changeset 3:090acf24fd3d
fix rotate bag
author | tatsuki |
---|---|
date | Sun, 29 Mar 2015 23:21:19 +0900 |
parents | d8f78957698f |
children | 3de906fb90d1 |
files | src/main/java/jp/ac/u_ryukyu/ie/cr/tatsuki/TreeMap/BlackNode.java src/main/java/jp/ac/u_ryukyu/ie/cr/tatsuki/TreeMap/Node.java src/main/java/jp/ac/u_ryukyu/ie/cr/tatsuki/TreeMap/TreeMap.java |
diffstat | 3 files changed, 7 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/tatsuki/TreeMap/BlackNode.java Sun Mar 29 20:57:39 2015 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/tatsuki/TreeMap/BlackNode.java Sun Mar 29 23:21:19 2015 +0900 @@ -49,9 +49,9 @@ return new RedNode<K,V>(right.getKey(), right.getValue(), leftChild, rightChild); } else if (spin == RL) { - Node<K, V> leftChild = new BlackNode<K,V>(getKey(), getValue(), left, right.left()); - Node<K, V> rightChild = new BlackNode<K,V>(right.right().getKey(), right.right().getValue(), right.right().left(), right.right().right()); - return new RedNode<K,V>(right.getKey(), right.getValue(), leftChild, rightChild); + Node<K, V> leftChild = new BlackNode<K,V>(getKey(), getValue(), left, right.left().left()); + Node<K, V> rightChild = new BlackNode<K,V>(right.getKey(), right.getValue(), right.left().right(), right.right()); + return new RedNode<K,V>(right.left().getKey(), right.left().getValue(), leftChild, rightChild); }
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/tatsuki/TreeMap/Node.java Sun Mar 29 20:57:39 2015 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/tatsuki/TreeMap/Node.java Sun Mar 29 23:21:19 2015 +0900 @@ -48,7 +48,8 @@ public Optional<V> getLoop(Comparable<? super K> key) { Node<K, V> cur = this; - do { + + while (cur.exitNode()) { int result = key.compareTo(cur.getKey()); if (result > 0) @@ -59,8 +60,7 @@ else if (result == 0) return Optional.ofNullable(cur.getValue()); - - } while (cur.exitNode()); + } return Optional.ofNullable(null); }
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/tatsuki/TreeMap/TreeMap.java Sun Mar 29 20:57:39 2015 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/tatsuki/TreeMap/TreeMap.java Sun Mar 29 23:21:19 2015 +0900 @@ -14,7 +14,7 @@ int size; public TreeMap() { - this.root = null; + this.root = new EmptyNode<>(); this.size = 0; }