Mercurial > hg > Members > shoshi > jungle > jungle-core
changeset 299:67ff36237722
implement redBlackTree deleteAttribute
author | tatsuki |
---|---|
date | Thu, 05 Jan 2017 21:56:24 +0900 |
parents | 1f132728ae40 |
children | b060ece7f8e4 |
files | src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/transaction/node/redBlackTree/RedBlackTreeNodeAttribute.java src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/transaction/node/redBlackTree/RedBlackTreeNodeChildren.java src/test/java/jp/ac/u_ryukyu/ie/cr/jungle/core/treeeditor/RedBlack/RedBlackTreeEditorAttributeTest.java |
diffstat | 3 files changed, 33 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/transaction/node/redBlackTree/RedBlackTreeNodeAttribute.java Thu Jan 05 21:27:46 2017 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/transaction/node/redBlackTree/RedBlackTreeNodeAttribute.java Thu Jan 05 21:56:24 2017 +0900 @@ -33,7 +33,17 @@ @Override public Either<Error, TreeNode> delete(String key) { - return null; + if (key == null) { + return DefaultEither.newA(NodeEditorError.NULL_VALUE_NOT_ALLOWED); + } + + if (null == attrs.get(key)) { + return DefaultEither.newA(NodeEditorError.DELETE_KEY_NOT_FOUND); + } + + TreeMap<String, ByteBuffer> newMap = attrs.delete(key); + ColorlessTreeNode newNode = node.createNode(newMap,balanceKey,value,node.left(),node.right()); + return DefaultEither.newB(newNode); } @Override
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/transaction/node/redBlackTree/RedBlackTreeNodeChildren.java Thu Jan 05 21:27:46 2017 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/transaction/node/redBlackTree/RedBlackTreeNodeChildren.java Thu Jan 05 21:56:24 2017 +0900 @@ -75,17 +75,22 @@ } + /** + * 赤黒木はPathを使ったノードの削除は行わない + * 本気出したら実装できるから + * 余裕ができたら実装しよう + */ @Override public Either<Error, TreeNode> deleteChildAt(int pos) { return null; } + @Override public Either<Error, TreeNode> replaceNode(int pos, TreeNode replacement) { if (!boundaryCheck(pos)) { return DefaultEither.newA(NodeEditorError.INDEX_OUT_OF_BOUNDS); } - ColorlessTreeNode newNode; if (pos == 0) { //左のノードを入れ替える場合 newNode = node.createNode(attrs,node.key(),node.value(),(ColorlessTreeNode) replacement,node.right());
--- a/src/test/java/jp/ac/u_ryukyu/ie/cr/jungle/core/treeeditor/RedBlack/RedBlackTreeEditorAttributeTest.java Thu Jan 05 21:27:46 2017 +0900 +++ b/src/test/java/jp/ac/u_ryukyu/ie/cr/jungle/core/treeeditor/RedBlack/RedBlackTreeEditorAttributeTest.java Thu Jan 05 21:56:24 2017 +0900 @@ -15,9 +15,6 @@ import java.nio.ByteBuffer; -/** - * Created by e115731 on 2017/01/05. - */ public class RedBlackTreeEditorAttributeTest { @Test public void RedBlackTreeEditorAttribute(){ @@ -41,21 +38,34 @@ path = path.add(1); ByteBuffer value = ByteBuffer.wrap(path.toString().getBytes()); Either<Error, JungleTreeEditor> either = editor.putAttribute(path, key, value); - Assert.assertFalse(either.isA()); //AttributeのPutが成功したかどうか + Assert.assertFalse(either.isA()); //AttributeのPutが成功したかどうか調べる editor = either.b(); either = editor.success(); Assert.assertFalse(either.isA()); JungleTree oldTree = tree.getOldTree(tree.revision() - 1).b(); TreeNode oldRoot = oldTree.getRootNode(); - TreeNode newRoot = tree.getRootNode(); - Assert.assertNotEquals(newRoot,oldRoot);// とりあえずルートがちゃんと入れ替えられているかを調べる + TreeNode attributePutedTreeRoot = tree.getRootNode(); + Assert.assertNotEquals(attributePutedTreeRoot,oldRoot);// とりあえずルートがちゃんと入れ替えられているかを調べる TreeNode editedNode = tree.getNodeOfPath(path).b(); TreeNode editedOldNode = oldTree.getNodeOfPath(path).b(); String putValue = editedNode.getAttributes().getString(key);//編集したノードからputしたAttributeを取得 Assert.assertEquals(putValue,path.toString()); ByteBuffer nullValue = editedOldNode.getAttributes().get(key);//編集前のノードから値を取得 nullが取れる Assert.assertNull(nullValue); + ByteBuffer oldRootValue = oldRoot.getAttributes().get(balanceKey); + ByteBuffer newRootValue = attributePutedTreeRoot.getAttributes().get(balanceKey);//rootとかがちゃんと複製されているかを調べる + Assert.assertEquals(oldRootValue,newRootValue); + editor = tree.getJungleTreeEditor(); + either = editor.deleteAttribute(path,key); + Assert.assertFalse(either.isA()); //Attributeのdeleteが成功したかどうか調べる + editor = either.b(); + either = editor.success(); + Assert.assertFalse(either.isA()); + + TreeNode AttributeDeletedNode = tree.getNodeOfPath(path).b();//Attributeがちゃんと削除できたかを調べる + nullValue = AttributeDeletedNode.getAttributes().get(key); + Assert.assertNull(nullValue); } }