Mercurial > hg > Members > shoshi > jungle > jungle-core
changeset 292:20fac8350822
add RedBlackJungleTree
line wrap: on
line diff
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/benchMark/DifferencialTree/DifferencialTreeBenchMark.java Sat Dec 31 03:30:14 2016 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/benchMark/DifferencialTree/DifferencialTreeBenchMark.java Tue Jan 03 21:27:55 2017 +0900 @@ -37,11 +37,12 @@ } private static void DifferenceJungleTreeBenchMark(Jungle jungle) { - for (int i = 1; i <= 10; i++) { + System.out.println("differencialTree"); + for (int i = 1; i <= 100; i++) { JungleTree tree = jungle.createNewDifferenceTree("Tree" + i); Long t1 = System.currentTimeMillis(); NodePath path = new DefaultNodePath(); - for (int j = 0; j < (200 * i ); j++) { + for (int j = 0; j < (20 * i ); j++) { JungleTreeEditor editor = tree.getJungleTreeEditor(); Either<Error, JungleTreeEditor> either = editor.putAttribute(path,"key", ByteBuffer.wrap("value".getBytes())); if (either.isA()) @@ -51,13 +52,14 @@ if (either.isA()) return ; } - + System.gc(); Long t2 = System.currentTimeMillis(); - System.out.println("Node count = " + (i * 200) + " : time = " + (t2 - t1)); + System.out.println((i * 20) + " " + (t2 - t1)); } } private static void defaultJungleTreeBenchMark(Jungle jungle) { + System.out.println("defaultTree"); for (int i = 1; i <= 10; i++) { JungleTree tree = jungle.createNewTree("Tree" + i); Long t1 = System.currentTimeMillis(); @@ -79,7 +81,7 @@ } Long t2 = System.currentTimeMillis(); - System.out.println("Node count = " + (i * 200) + " : time = " + (t2 - t1)); + System.out.println((i * 200) + " " + (t2 - t1)); } } }
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/DefaultJungle.java Sat Dec 31 03:30:14 2016 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/DefaultJungle.java Tue Jan 03 21:27:55 2017 +0900 @@ -10,21 +10,24 @@ import jp.ac.u_ryukyu.ie.cr.jungle.store.logger.TreeOperationLog; import jp.ac.u_ryukyu.ie.cr.jungle.store.nodepath.DefaultNodePath; import jp.ac.u_ryukyu.ie.cr.jungle.store.operations.TreeOperation; -import jp.ac.u_ryukyu.ie.cr.jungle.transaction.DefaultTreeContext; -import jp.ac.u_ryukyu.ie.cr.jungle.transaction.DifferenceTreeContext; +import jp.ac.u_ryukyu.ie.cr.jungle.transaction.context.DefaultTreeContext; +import jp.ac.u_ryukyu.ie.cr.jungle.transaction.context.DifferenceTreeContext; import jp.ac.u_ryukyu.ie.cr.jungle.transaction.editor.jungleTreeEditor.JungleTreeEditor; import jp.ac.u_ryukyu.ie.cr.jungle.transaction.editor.treeEditor.DefaultTreeEditor; import jp.ac.u_ryukyu.ie.cr.jungle.transaction.editor.treeEditor.DifferenceTreeEditor; +import jp.ac.u_ryukyu.ie.cr.jungle.transaction.editor.treeEditor.RedBlackTreeEditor; import jp.ac.u_ryukyu.ie.cr.jungle.transaction.editor.treeEditor.TreeEditor; import jp.ac.u_ryukyu.ie.cr.jungle.transaction.node.Default.DefaultTreeNode; import jp.ac.u_ryukyu.ie.cr.jungle.transaction.node.Differencial.DifferencialTreeNode; import jp.ac.u_ryukyu.ie.cr.jungle.transaction.node.TreeNode; +import jp.ac.u_ryukyu.ie.cr.jungle.transaction.node.redBlackTree.EmptyTreeNode; import jp.ac.u_ryukyu.ie.cr.jungle.traverser.DefaultTraverser; import jp.ac.u_ryukyu.ie.cr.jungle.traverser.InterfaceTraverser; import jp.ac.u_ryukyu.ie.cr.jungle.traverser.Traverser; import jp.ac.u_ryukyu.ie.cr.jungle.tree.DefaultJungleTree; import jp.ac.u_ryukyu.ie.cr.jungle.tree.DifferenceListJungleTree; import jp.ac.u_ryukyu.ie.cr.jungle.tree.JungleTree; +import jp.ac.u_ryukyu.ie.cr.jungle.tree.RedBlackJungleTree; import jp.ac.u_ryukyu.ie.cr.jungle.util.Either; import jp.ac.u_ryukyu.ie.cr.jungle.util.Error.Error; @@ -38,6 +41,7 @@ private String uuid; private TreeEditor treeEditor; private TreeEditor differenceEditor; + private TreeEditor redBlackTreeEditor; public static void main(String args[]) { DefaultJungle j = new DefaultJungle(null, "hoge", new DefaultTraverser()); @@ -60,6 +64,7 @@ this.uuid = uuid; this.treeEditor = new DefaultTreeEditor(traverser); this.differenceEditor = new DifferenceTreeEditor(traverser); + this.redBlackTreeEditor = new RedBlackTreeEditor(traverser); } @Override @@ -139,7 +144,7 @@ }; InterfaceTraverser traverser = new InterfaceTraverser(rootNode, true); - TreeContext tc = new DifferenceTreeContext(rootNode, rootNode,null ,list, uuid, name, 0, traverser); + TreeContext tc = new DifferenceTreeContext(rootNode, rootNode, null, list, uuid, name, 0, traverser); JungleTree newTree = new DifferenceListJungleTree(tc, uuid, journal.getWriter(), differenceEditor); if (trees.putIfAbsent(name, newTree) != null) { return null; @@ -148,6 +153,42 @@ } @Override + public JungleTree createNewRedBlackTree(String name, String balanceKey) { + ChangeList list = new ChangeList() { + @Override + public Iterator<TreeOperation> iterator() { + List<TreeOperation> nil = new List<>(); + return nil.iterator(); + } + + @Override + public String uuid() { + return uuid; + } + + @Override + public String getTreeName() { + return name; + } + + @Override + public TreeOperationLog getLog() { + return new DefaultTreeOperationLog(); + } + + }; + TreeNode rootNode = new EmptyTreeNode(); + InterfaceTraverser traverser = new InterfaceTraverser(rootNode, true); + TreeContext tc = new DefaultTreeContext(rootNode, null, list, uuid, name, 0, traverser); + JungleTree newTree = new RedBlackJungleTree(tc, uuid, journal.getWriter(), redBlackTreeEditor, balanceKey); + if (trees.putIfAbsent(name, newTree) != null) { + return null; + } + return newTree; + } + + + @Override public Iterator<String> getTreeNames() { Enumeration<String> treeNames = trees.keys(); return new Iterator<String>() {
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/Jungle.java Sat Dec 31 03:30:14 2016 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/Jungle.java Tue Jan 03 21:27:55 2017 +0900 @@ -19,4 +19,6 @@ public Iterator<String> getTreeNames(); + + public JungleTree createNewRedBlackTree(String treeName, String balanceKey); }
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/data/list/List.java Sat Dec 31 03:30:14 2016 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/data/list/List.java Tue Jan 03 21:27:55 2017 +0900 @@ -153,7 +153,4 @@ } return newList; } - - - }
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/store/Command.java Sat Dec 31 03:30:14 2016 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/store/Command.java Tue Jan 03 21:27:55 2017 +0900 @@ -8,5 +8,6 @@ PUT_ATTRIBUTE, DELETE_ATTRIBUTE, REPLACE_ROOT, - MOVE_CHILD; + MOVE_CHILD, + APPEND_CHILD_AND_PUT_ATTRIBUTE; } \ No newline at end of file
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/store/logger/LoggingChildren.java Sat Dec 31 03:30:14 2016 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/store/logger/LoggingChildren.java Tue Jan 03 21:27:55 2017 +0900 @@ -2,15 +2,14 @@ import jp.ac.u_ryukyu.ie.cr.jungle.core.Children; +import jp.ac.u_ryukyu.ie.cr.jungle.store.operations.*; import jp.ac.u_ryukyu.ie.cr.jungle.transaction.node.TreeNode; -import jp.ac.u_ryukyu.ie.cr.jungle.store.operations.AppendChildAtOperation; -import jp.ac.u_ryukyu.ie.cr.jungle.store.operations.ChildMoveOperation; -import jp.ac.u_ryukyu.ie.cr.jungle.store.operations.DeleteChildAtOperation; -import jp.ac.u_ryukyu.ie.cr.jungle.store.operations.NodeOperation; import jp.ac.u_ryukyu.ie.cr.jungle.util.DefaultEither; import jp.ac.u_ryukyu.ie.cr.jungle.util.Either; import jp.ac.u_ryukyu.ie.cr.jungle.util.Error.Error; +import java.nio.ByteBuffer; + public class LoggingChildren { private final TreeNode wrap; @@ -47,6 +46,12 @@ return edit(addNewChildAt); } + + public Either<Error,LoggingNode> addNewChildAndPutAttribute(int pos, String key, ByteBuffer value) { + NodeOperation addnewChildAndPutAttribute = new AddNewChildAndPutAttribute(pos, key, value); + return edit(addnewChildAndPutAttribute); + } + public Either<Error,LoggingNode> deleteChildAt(final int _pos) { NodeOperation deleteChildAt = new DeleteChildAtOperation(_pos);
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/store/nodepath/DefaultNodePath.java Sat Dec 31 03:30:14 2016 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/store/nodepath/DefaultNodePath.java Tue Jan 03 21:27:55 2017 +0900 @@ -19,6 +19,10 @@ path = new List<Integer>().addLast(-1); } + public DefaultNodePath(int num) { + path = new List<Integer>().addLast(num); + } + public DefaultNodePath(String nodePath) { List<Integer> _path = new List<>(); String[] nums = nodePath.split(",");
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/store/operations/AddNewChildAndPutAttribute.java Tue Jan 03 21:27:55 2017 +0900 @@ -0,0 +1,49 @@ +package jp.ac.u_ryukyu.ie.cr.jungle.store.operations; + + +import jp.ac.u_ryukyu.ie.cr.jungle.store.Command; +import jp.ac.u_ryukyu.ie.cr.jungle.transaction.node.TreeNode; +import jp.ac.u_ryukyu.ie.cr.jungle.transaction.node.TreeNodeChildren; +import jp.ac.u_ryukyu.ie.cr.jungle.util.Either; +import jp.ac.u_ryukyu.ie.cr.jungle.util.Error.Error; + +import java.nio.ByteBuffer; + +public class AddNewChildAndPutAttribute implements NodeOperation { + + private String key; + private ByteBuffer value; + private int pos; + + public AddNewChildAndPutAttribute(int pos, String key, ByteBuffer value) { + this.key = key; + this.value = value; + this.pos = pos; + } + + @Override + public Command getCommand() { + return Command.APPEND_CHILD_AND_PUT_ATTRIBUTE; + } + + @Override + public Either<Error, TreeNode> invoke(TreeNode target) { + TreeNodeChildren children = target.getChildren(); + return children.addNewChildAndPutAttribtue(pos, key, value); + } + + @Override + public int getPosition() { + return -2; + } + + @Override + public String getKey() { + return key; + } + + @Override + public ByteBuffer getValue() { + return value; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/store/trasnformer/AppendChildAndPutAttribute.java Tue Jan 03 21:27:55 2017 +0900 @@ -0,0 +1,51 @@ +package jp.ac.u_ryukyu.ie.cr.jungle.store.trasnformer; + +import jp.ac.u_ryukyu.ie.cr.jungle.store.logger.LoggingNode; +import jp.ac.u_ryukyu.ie.cr.jungle.store.logger.OperationLog; +import jp.ac.u_ryukyu.ie.cr.jungle.transaction.node.TreeNode; +import jp.ac.u_ryukyu.ie.cr.jungle.util.DefaultEither; +import jp.ac.u_ryukyu.ie.cr.jungle.util.Either; +import jp.ac.u_ryukyu.ie.cr.jungle.util.Error.Error; + +import java.nio.ByteBuffer; + +/** + * Created by e115731 on 2017/01/02. + */ +public class AppendChildAndPutAttribute implements NodeEditor { + + private final int pos; + private final String key; + private final ByteBuffer value; + + public AppendChildAndPutAttribute(String key, ByteBuffer value, int pos) { + this.key = key; + this.value = value; + this.pos = pos; + } + + public Either<Error, LoggingNode> _edit(LoggingNode _e) { + Either<Error, LoggingNode> either = _e.getChildren().addNewChildAndPutAttribute(pos, key, value); + if (either.isA()) { + // error + return either; + } + return DefaultEither.newB(either.b()); + } + + @Override + public Either<Error, LoggingNode> edit(TreeNode _e) { + LoggingNode logNode = wrap(_e); + return _edit(logNode); + } + + @Override + public LoggingNode wrap(TreeNode newRoot, TreeNode editedNode, OperationLog operationLog) { + return new LoggingNode(newRoot, editedNode, operationLog); + } + + public LoggingNode wrap(TreeNode node) { + return new LoggingNode(node); + } + +}
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/transaction/DefaultTreeContext.java Sat Dec 31 03:30:14 2016 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,91 +0,0 @@ -package jp.ac.u_ryukyu.ie.cr.jungle.transaction; - - -import jp.ac.u_ryukyu.ie.cr.jungle.persistent.ChangeList; -import jp.ac.u_ryukyu.ie.cr.jungle.store.TreeContext; -import jp.ac.u_ryukyu.ie.cr.jungle.store.index.Index; -import jp.ac.u_ryukyu.ie.cr.jungle.store.index.ParentIndex; -import jp.ac.u_ryukyu.ie.cr.jungle.store.operations.TreeOperation; -import jp.ac.u_ryukyu.ie.cr.jungle.transaction.node.TreeNode; -import jp.ac.u_ryukyu.ie.cr.jungle.traverser.InterfaceTraverser; - -public class DefaultTreeContext implements TreeContext { - private final TreeNode root; - private final TreeContext previous; - private final ChangeList changeList; - private final String uuid; - private final String treeName; - private final long revision; - private final InterfaceTraverser traverser; - - public DefaultTreeContext(TreeNode _node, TreeContext _prev, ChangeList _log, String _uuid, String _treeName, long _revision, InterfaceTraverser traverser) { - this.root = _node; - this.previous = _prev; - this.changeList = _log; - this.uuid = _uuid; - this.treeName = _treeName; - this.revision = _revision; - this.traverser = traverser; - } - - - @Override - public TreeNode getRoot() { - return root; - } - - @Override - public TreeNode getAppendedNode(){ - return null; // not use - } - - @Override - public boolean setAppendedNode(TreeNode AppendedNode) { - return false; // 使わない - } - - @Override - public TreeContext prev() { - return previous; - } - - @Override - public ChangeList getChangeList() { - return changeList; - } - - @Override - public String uuid() { - return uuid; - } - - @Override - public String getTreeName() { - return treeName; - } - - @Override - public long revision() { - return revision; - } - - @Override - public Iterable<TreeOperation> getOperations() { - return changeList; - } - - @Override - public Index getIndex() { - return traverser.getIndex(); - } - - @Override - public ParentIndex getParentIndex() { - return traverser.getParentIndex(); - } - - @Override - public InterfaceTraverser getTraverser() { - return traverser; - } -}
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/transaction/DifferenceTreeContext.java Sat Dec 31 03:30:14 2016 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,97 +0,0 @@ -package jp.ac.u_ryukyu.ie.cr.jungle.transaction; - -import jp.ac.u_ryukyu.ie.cr.jungle.persistent.ChangeList; -import jp.ac.u_ryukyu.ie.cr.jungle.store.TreeContext; -import jp.ac.u_ryukyu.ie.cr.jungle.store.index.Index; -import jp.ac.u_ryukyu.ie.cr.jungle.store.index.ParentIndex; -import jp.ac.u_ryukyu.ie.cr.jungle.store.operations.TreeOperation; -import jp.ac.u_ryukyu.ie.cr.jungle.transaction.node.TreeNode; -import jp.ac.u_ryukyu.ie.cr.jungle.traverser.InterfaceTraverser; - - -public class DifferenceTreeContext implements TreeContext { - private final TreeNode root; - private TreeNode appendedNode; - private final TreeContext previous; - private final ChangeList changeList; - private final String uuid; - private final String treeName; - private final long revision; - private final InterfaceTraverser traverser; - - - public DifferenceTreeContext(TreeNode root, TreeNode appendedNode, TreeContext _prev, ChangeList _log, String _uuid, String _treeName, long _revision, InterfaceTraverser traverser) { - this.root = root; - this.appendedNode = appendedNode; - this.previous = _prev; - this.changeList = _log; - this.uuid = _uuid; - this.treeName = _treeName; - this.revision = _revision; - this.traverser = traverser; - } - - - @Override - public TreeNode getRoot() { - return root; - } - - @Override - public TreeNode getAppendedNode(){ - return appendedNode; - } - - @Override - public boolean setAppendedNode(TreeNode appendedNode) { - if (this.appendedNode != null) - return false; - this.appendedNode = appendedNode; - return true; - } - - @Override - public TreeContext prev() { - return previous; - } - - @Override - public ChangeList getChangeList() { - return changeList; - } - - @Override - public String uuid() { - return uuid; - } - - @Override - public String getTreeName() { - return treeName; - } - - @Override - public long revision() { - return revision; - } - - @Override - public Iterable<TreeOperation> getOperations() { - return changeList; - } - - @Override - public Index getIndex() { - return traverser.getIndex(); - } - - @Override - public ParentIndex getParentIndex() { - return traverser.getParentIndex(); - } - - @Override - public InterfaceTraverser getTraverser() { - return traverser; - } -}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/transaction/context/DefaultTreeContext.java Tue Jan 03 21:27:55 2017 +0900 @@ -0,0 +1,91 @@ +package jp.ac.u_ryukyu.ie.cr.jungle.transaction.context; + + +import jp.ac.u_ryukyu.ie.cr.jungle.persistent.ChangeList; +import jp.ac.u_ryukyu.ie.cr.jungle.store.TreeContext; +import jp.ac.u_ryukyu.ie.cr.jungle.store.index.Index; +import jp.ac.u_ryukyu.ie.cr.jungle.store.index.ParentIndex; +import jp.ac.u_ryukyu.ie.cr.jungle.store.operations.TreeOperation; +import jp.ac.u_ryukyu.ie.cr.jungle.transaction.node.TreeNode; +import jp.ac.u_ryukyu.ie.cr.jungle.traverser.InterfaceTraverser; + +public class DefaultTreeContext implements TreeContext { + private final TreeNode root; + private final TreeContext previous; + private final ChangeList changeList; + private final String uuid; + private final String treeName; + private final long revision; + private final InterfaceTraverser traverser; + + public DefaultTreeContext(TreeNode _node, TreeContext _prev, ChangeList _log, String _uuid, String _treeName, long _revision, InterfaceTraverser traverser) { + this.root = _node; + this.previous = _prev; + this.changeList = _log; + this.uuid = _uuid; + this.treeName = _treeName; + this.revision = _revision; + this.traverser = traverser; + } + + + @Override + public TreeNode getRoot() { + return root; + } + + @Override + public TreeNode getAppendedNode(){ + return null; // not use + } + + @Override + public boolean setAppendedNode(TreeNode AppendedNode) { + return false; // 使わない + } + + @Override + public TreeContext prev() { + return previous; + } + + @Override + public ChangeList getChangeList() { + return changeList; + } + + @Override + public String uuid() { + return uuid; + } + + @Override + public String getTreeName() { + return treeName; + } + + @Override + public long revision() { + return revision; + } + + @Override + public Iterable<TreeOperation> getOperations() { + return changeList; + } + + @Override + public Index getIndex() { + return traverser.getIndex(); + } + + @Override + public ParentIndex getParentIndex() { + return traverser.getParentIndex(); + } + + @Override + public InterfaceTraverser getTraverser() { + return traverser; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/transaction/context/DifferenceTreeContext.java Tue Jan 03 21:27:55 2017 +0900 @@ -0,0 +1,97 @@ +package jp.ac.u_ryukyu.ie.cr.jungle.transaction.context; + +import jp.ac.u_ryukyu.ie.cr.jungle.persistent.ChangeList; +import jp.ac.u_ryukyu.ie.cr.jungle.store.TreeContext; +import jp.ac.u_ryukyu.ie.cr.jungle.store.index.Index; +import jp.ac.u_ryukyu.ie.cr.jungle.store.index.ParentIndex; +import jp.ac.u_ryukyu.ie.cr.jungle.store.operations.TreeOperation; +import jp.ac.u_ryukyu.ie.cr.jungle.transaction.node.TreeNode; +import jp.ac.u_ryukyu.ie.cr.jungle.traverser.InterfaceTraverser; + + +public class DifferenceTreeContext implements TreeContext { + private final TreeNode root; + private TreeNode appendedNode; + private final TreeContext previous; + private final ChangeList changeList; + private final String uuid; + private final String treeName; + private final long revision; + private final InterfaceTraverser traverser; + + + public DifferenceTreeContext(TreeNode root, TreeNode appendedNode, TreeContext _prev, ChangeList _log, String _uuid, String _treeName, long _revision, InterfaceTraverser traverser) { + this.root = root; + this.appendedNode = appendedNode; + this.previous = _prev; + this.changeList = _log; + this.uuid = _uuid; + this.treeName = _treeName; + this.revision = _revision; + this.traverser = traverser; + } + + + @Override + public TreeNode getRoot() { + return root; + } + + @Override + public TreeNode getAppendedNode(){ + return appendedNode; + } + + @Override + public boolean setAppendedNode(TreeNode appendedNode) { + if (this.appendedNode != null) + return false; + this.appendedNode = appendedNode; + return true; + } + + @Override + public TreeContext prev() { + return previous; + } + + @Override + public ChangeList getChangeList() { + return changeList; + } + + @Override + public String uuid() { + return uuid; + } + + @Override + public String getTreeName() { + return treeName; + } + + @Override + public long revision() { + return revision; + } + + @Override + public Iterable<TreeOperation> getOperations() { + return changeList; + } + + @Override + public Index getIndex() { + return traverser.getIndex(); + } + + @Override + public ParentIndex getParentIndex() { + return traverser.getParentIndex(); + } + + @Override + public InterfaceTraverser getTraverser() { + return traverser; + } +}
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/transaction/editor/jungleTreeEditor/DefaultJungleTreeEditor.java Sat Dec 31 03:30:14 2016 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/transaction/editor/jungleTreeEditor/DefaultJungleTreeEditor.java Tue Jan 03 21:27:55 2017 +0900 @@ -53,7 +53,7 @@ OperationLog newLog = newLogging.getOperationLog(); TreeNode newNode = newLogging.getWrap(); TreeNode editedNode = newLogging.getEditedNode(); - List<TreeNode> newEditendNodeList = editedNodeList.add(0,editedNode); + List<TreeNode> newEditendNodeList = editedNodeList.add(0, editedNode); IterableConverter.Converter<TreeOperation, NodeOperation> converter = new IterableConverter.Converter<TreeOperation, NodeOperation>() { @Override public TreeOperation conv(NodeOperation _b) { @@ -81,6 +81,12 @@ } @Override + public Either<Error, JungleTreeEditor> addNewChildAndPutAttribute(NodePath path, int pos, String key, ByteBuffer value) { + AppendChildAndPutAttribute appendChildAndPutAttribute = new AppendChildAndPutAttribute(key,value,pos); + return _edit(path,appendChildAndPutAttribute); + } + + @Override public Either<Error, JungleTreeEditor> deleteChildAt(NodePath _path, int _pos) { DeleteChildAt deleteChildAt = new DeleteChildAt(_pos); return _edit(_path, deleteChildAt);
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/transaction/editor/jungleTreeEditor/DifferenceJungleTreeEditor.java Sat Dec 31 03:30:14 2016 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/transaction/editor/jungleTreeEditor/DifferenceJungleTreeEditor.java Tue Jan 03 21:27:55 2017 +0900 @@ -99,6 +99,12 @@ } @Override + public Either<Error, JungleTreeEditor> addNewChildAndPutAttribute(NodePath path, int pos, String key, ByteBuffer value) { + AppendChildAndPutAttribute appendChildAndPutAttribute = new AppendChildAndPutAttribute(key,value,pos); + return _edit(path,appendChildAndPutAttribute); + } + + @Override public Either<Error, JungleTreeEditor> deleteChildAt(NodePath _path, int _pos) { DeleteChildAt deleteChildAt = new DeleteChildAt(_pos); return _edit(_path, deleteChildAt);
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/transaction/editor/jungleTreeEditor/JungleTreeEditor.java Sat Dec 31 03:30:14 2016 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/transaction/editor/jungleTreeEditor/JungleTreeEditor.java Tue Jan 03 21:27:55 2017 +0900 @@ -11,6 +11,8 @@ public Either<Error, JungleTreeEditor> addNewChildAt(NodePath path, int pos); + public Either<Error, JungleTreeEditor> addNewChildAndPutAttribute(NodePath path, int pos, String key, ByteBuffer value); + public Either<Error, JungleTreeEditor> deleteChildAt(NodePath path, int pos); public Either<Error, JungleTreeEditor> putAttribute(NodePath path, String key, ByteBuffer value); @@ -25,5 +27,5 @@ public Either<Error, JungleTreeEditor> flushSuccess(); - public Either<Error, JungleTreeEditor> moveChild(NodePath path,int childNum ,String move); + public Either<Error, JungleTreeEditor> moveChild(NodePath path, int childNum, String move); }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/transaction/editor/jungleTreeEditor/RedBlackJungleTreeEditor.java Tue Jan 03 21:27:55 2017 +0900 @@ -0,0 +1,140 @@ +package jp.ac.u_ryukyu.ie.cr.jungle.transaction.editor.jungleTreeEditor; + +import jp.ac.u_ryukyu.ie.cr.jungle.data.list.List; +import jp.ac.u_ryukyu.ie.cr.jungle.store.logger.DefaultTreeOperationLog; +import jp.ac.u_ryukyu.ie.cr.jungle.store.logger.LoggingNode; +import jp.ac.u_ryukyu.ie.cr.jungle.store.logger.OperationLog; +import jp.ac.u_ryukyu.ie.cr.jungle.store.logger.TreeOperationLog; +import jp.ac.u_ryukyu.ie.cr.jungle.store.nodepath.NodePath; +import jp.ac.u_ryukyu.ie.cr.jungle.store.operations.DefaultTreeOperation; +import jp.ac.u_ryukyu.ie.cr.jungle.store.operations.NodeOperation; +import jp.ac.u_ryukyu.ie.cr.jungle.store.operations.TreeOperation; +import jp.ac.u_ryukyu.ie.cr.jungle.store.trasnformer.AppendChildAndPutAttribute; +import jp.ac.u_ryukyu.ie.cr.jungle.store.trasnformer.NodeEditor; +import jp.ac.u_ryukyu.ie.cr.jungle.transaction.editor.treeEditor.TreeEditor; +import jp.ac.u_ryukyu.ie.cr.jungle.transaction.manager.TransactionManager; +import jp.ac.u_ryukyu.ie.cr.jungle.transaction.node.TreeNode; +import jp.ac.u_ryukyu.ie.cr.jungle.util.DefaultEither; +import jp.ac.u_ryukyu.ie.cr.jungle.util.Either; +import jp.ac.u_ryukyu.ie.cr.jungle.util.Error.Error; +import jp.ac.u_ryukyu.ie.cr.jungle.util.IterableConverter; + +import java.nio.ByteBuffer; + +import static jp.ac.u_ryukyu.ie.cr.jungle.util.Error.JungleTreeError.NOT_USE_METHOD; + + +public class RedBlackJungleTreeEditor implements JungleTreeEditor { + private final TransactionManager txManager; + private final TreeNode root; + private final TreeEditor editor; + private final TreeOperationLog log; + private final List<TreeNode> editedNodeList; + private final String balanceKey; + + public RedBlackJungleTreeEditor(TreeNode _root, String balanceKey, TransactionManager _txManager, TreeEditor _editor) { + this(_root, balanceKey, _txManager, _editor, new DefaultTreeOperationLog(), new List<>()); + } + + + public RedBlackJungleTreeEditor(TreeNode newNode, String balanceKey, TransactionManager _txManager, TreeEditor _editor, TreeOperationLog _log, List<TreeNode> editedNodeList) { + this.root = newNode; + this.txManager = _txManager; + this.editor = _editor; + this.log = _log; + this.editedNodeList = editedNodeList; + this.balanceKey = balanceKey; + } + + + private Either<Error, JungleTreeEditor> _edit(final NodePath _path, NodeEditor _e) { + Either<Error, LoggingNode> editEither = editor.edit(root, _path, _e); + + if (editEither.isA()) { + return DefaultEither.newA(editEither.a()); + } + + LoggingNode newLogging = editEither.b(); + OperationLog newLog = newLogging.getOperationLog(); + TreeNode newNode = newLogging.getWrap(); + TreeNode editedNode = newLogging.getEditedNode(); + List<TreeNode> newEditendNodeList = editedNodeList.add(0, editedNode); + IterableConverter.Converter<TreeOperation, NodeOperation> converter = new IterableConverter.Converter<TreeOperation, NodeOperation>() { + @Override + public TreeOperation conv(NodeOperation _b) { + return new DefaultTreeOperation(_path, _b); + } + }; + + Iterable<TreeOperation> iterable = new IterableConverter<>(newLog, converter); + DefaultTreeOperationLog treeOperationLog = new DefaultTreeOperationLog(iterable, newLog.length()); + TreeOperationLog newTreeOpLog = log.append(treeOperationLog); + JungleTreeEditor newEditor = new RedBlackJungleTreeEditor(newNode, balanceKey, txManager, editor, newTreeOpLog, newEditendNodeList); + return DefaultEither.newB(newEditor); + } + + /** + * 赤黒木なのでNodeを入れた後は回転処理が行われるので + * Pathは無視する + * Pathがあるのはインターフェスで定義されているmethodに合わせるため + */ + @Override + public Either<Error, JungleTreeEditor> addNewChildAndPutAttribute(NodePath path, int pos, String key, ByteBuffer value) { + AppendChildAndPutAttribute appendChildAndPutAttribute = new AppendChildAndPutAttribute(key,value,pos); + return _edit(path,appendChildAndPutAttribute); + } + + @Override + public Either<Error, JungleTreeEditor> addNewChildAt(NodePath path, int _pos) { + ByteBuffer value = ByteBuffer.wrap("defaultValue".getBytes()); + return addNewChildAndPutAttribute(path, 0, balanceKey, value); + } + + @Override + public Either<Error, JungleTreeEditor> deleteChildAt(NodePath _path, int _pos) { + //DeleteChildAt deleteChildAt = new DeleteChildAt(_pos); + //return _edit(_path, deleteChildAt); + return null; + } + + @Override + public Either<Error, JungleTreeEditor> putAttribute(NodePath _path, String _key, ByteBuffer _value) { + //PutAttribute putAttribute = new PutAttribute(_key, _value); + // return _edit(_path, putAttribute); + return null; + } + + @Override + public Either<Error, JungleTreeEditor> deleteAttribute(NodePath _path, String _key) { + // DeleteAttribute deleteAttribute = new DeleteAttribute(_key); + // return _edit(_path, deleteAttribute); + return null; + } + + @Override + public Either<Error, JungleTreeEditor> moveChild(NodePath path, int childNum, String move) { + return DefaultEither.newA(NOT_USE_METHOD); //赤黒木だから使わない + } + + @Override + public Either<Error, JungleTreeEditor> replaceNewRootNode() { + return DefaultEither.newA(NOT_USE_METHOD); // 赤黒木だから使わない + } + + @Override + public Either<Error, JungleTreeEditor> edit(NodePath _path, NodeEditor _editor) { + return _edit(_path, _editor); + } + + + @Override + public Either<Error, JungleTreeEditor> success() { + return null; + } + + @Override + public Either<Error, JungleTreeEditor> flushSuccess() { + return null; + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/transaction/editor/treeEditor/RedBlackTreeEditor.java Tue Jan 03 21:27:55 2017 +0900 @@ -0,0 +1,77 @@ +package jp.ac.u_ryukyu.ie.cr.jungle.transaction.editor.treeEditor; + +import jp.ac.u_ryukyu.ie.cr.jungle.data.list.List; +import jp.ac.u_ryukyu.ie.cr.jungle.store.logger.LoggingNode; +import jp.ac.u_ryukyu.ie.cr.jungle.store.nodepath.NodePath; +import jp.ac.u_ryukyu.ie.cr.jungle.store.trasnformer.NodeEditor; +import jp.ac.u_ryukyu.ie.cr.jungle.transaction.node.TreeNode; +import jp.ac.u_ryukyu.ie.cr.jungle.transaction.node.TreeNodeChildren; +import jp.ac.u_ryukyu.ie.cr.jungle.traverser.*; +import jp.ac.u_ryukyu.ie.cr.jungle.util.DefaultEither; +import jp.ac.u_ryukyu.ie.cr.jungle.util.Either; +import jp.ac.u_ryukyu.ie.cr.jungle.util.Error.Error; + +/** + * Created by e115731 on 2017/01/02. + */ +public class RedBlackTreeEditor implements TreeEditor { + + private final Traverser traverser; + + public RedBlackTreeEditor(Traverser traverser) { + this.traverser = traverser; + } + + @Override + public Either<Error, LoggingNode> edit(TreeNode root, NodePath path, NodeEditor editor) { + if (path.get(0) == -2) + return redBlackTreeNodeEdit(root, editor); + Evaluator e = new DefaultEvaluator(path); + Either<Error, Traversal> traverseEither = traverser.traverse(root, e); + if (traverseEither.isA()) { + return DefaultEither.newA(traverseEither.a()); + } + Traversal traversal = traverseEither.b(); + TreeNode target = traversal.destination(); + Either<Error, LoggingNode> either = editor.edit(target); + if (either.isA()) { + return DefaultEither.newA(either.a()); + } + LoggingNode newWrap = either.b(); + newWrap.setEditedNode(target); + return clone(newWrap, traversal, editor); + } + + private Either<Error, LoggingNode> redBlackTreeNodeEdit(TreeNode root, NodeEditor editor) { + return editor.edit(root); + } + + private Either<Error, LoggingNode> clone(LoggingNode newWrap, Traversal traversal, NodeEditor editor) { + List<Direction<TreeNode>> path = new List<>(); + for (Direction<TreeNode> direction : traversal) { + path = path.addLast(direction); + } + + Direction<TreeNode> editedNodeDirection = path.head(); + + // top + int pos = editedNodeDirection.getPosition(); + TreeNode child = newWrap.getWrap(); + for (Direction<TreeNode> parentDirection : path.deleteHead()) { + + TreeNodeChildren chs = parentDirection.getTarget().getChildren(); + + Either<Error, TreeNode> ret = chs.replaceNode(pos, child); + if (ret.isA()) { + return DefaultEither.newA(ret.a()); + } + + child = ret.b(); + pos = parentDirection.getPosition(); + } + + TreeNode newRoot = child; + LoggingNode logNode = editor.wrap(newRoot, newWrap.getEditedNode(), newWrap.getOperationLog()); + return DefaultEither.newB(logNode); + } +}
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/transaction/manager/DefaultTransactionManager.java Sat Dec 31 03:30:14 2016 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/transaction/manager/DefaultTransactionManager.java Tue Jan 03 21:27:55 2017 +0900 @@ -9,7 +9,7 @@ import jp.ac.u_ryukyu.ie.cr.jungle.store.index.ParentIndex; import jp.ac.u_ryukyu.ie.cr.jungle.store.logger.TreeOperationLog; import jp.ac.u_ryukyu.ie.cr.jungle.store.operations.TreeOperation; -import jp.ac.u_ryukyu.ie.cr.jungle.transaction.DefaultTreeContext; +import jp.ac.u_ryukyu.ie.cr.jungle.transaction.context.DefaultTreeContext; import jp.ac.u_ryukyu.ie.cr.jungle.transaction.node.TreeNode; import jp.ac.u_ryukyu.ie.cr.jungle.traverser.InterfaceTraverser; import jp.ac.u_ryukyu.ie.cr.jungle.util.DefaultEither;
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/transaction/manager/DifferenceTransactionManager.java Sat Dec 31 03:30:14 2016 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/transaction/manager/DifferenceTransactionManager.java Tue Jan 03 21:27:55 2017 +0900 @@ -11,7 +11,7 @@ import jp.ac.u_ryukyu.ie.cr.jungle.store.operations.Commit; import jp.ac.u_ryukyu.ie.cr.jungle.store.operations.NodeOperation; import jp.ac.u_ryukyu.ie.cr.jungle.store.operations.TreeOperation; -import jp.ac.u_ryukyu.ie.cr.jungle.transaction.DifferenceTreeContext; +import jp.ac.u_ryukyu.ie.cr.jungle.transaction.context.DifferenceTreeContext; import jp.ac.u_ryukyu.ie.cr.jungle.transaction.node.TreeNode; import jp.ac.u_ryukyu.ie.cr.jungle.transaction.node.TreeNodeChildren; import jp.ac.u_ryukyu.ie.cr.jungle.traverser.InterfaceTraverser;
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/transaction/node/Default/DefaultTreeNode.java Sat Dec 31 03:30:14 2016 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/transaction/node/Default/DefaultTreeNode.java Tue Jan 03 21:27:55 2017 +0900 @@ -53,6 +53,11 @@ @Override public int compareTo(TreeNode o) { - return this.hashCode() - o.hashCode(); + return this.getHash() - o.getHash(); + } + + @Override + public int getHash() { + return this.hashCode(); } }
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/transaction/node/Default/DefaultTreeNodeAttribute.java Sat Dec 31 03:30:14 2016 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/transaction/node/Default/DefaultTreeNodeAttribute.java Tue Jan 03 21:27:55 2017 +0900 @@ -110,4 +110,5 @@ public boolean contain(String key) { return attrs.get(key) != null; } + }
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/transaction/node/Default/DefaultTreeNodeChildren.java Sat Dec 31 03:30:14 2016 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/transaction/node/Default/DefaultTreeNodeChildren.java Tue Jan 03 21:27:55 2017 +0900 @@ -5,6 +5,7 @@ import jp.ac.u_ryukyu.ie.cr.jungle.data.treemap.TreeMap; import jp.ac.u_ryukyu.ie.cr.jungle.store.trasnformer.NodeEditorError; import jp.ac.u_ryukyu.ie.cr.jungle.transaction.node.TreeNode; +import jp.ac.u_ryukyu.ie.cr.jungle.transaction.node.TreeNodeAttributes; import jp.ac.u_ryukyu.ie.cr.jungle.transaction.node.TreeNodeChildren; import jp.ac.u_ryukyu.ie.cr.jungle.util.DefaultEither; import jp.ac.u_ryukyu.ie.cr.jungle.util.Either; @@ -14,6 +15,8 @@ import java.nio.ByteBuffer; import java.util.Iterator; +import static jp.ac.u_ryukyu.ie.cr.jungle.util.Error.TreeNodeError.PUT_ATTRIBUTE_ERROR; + public class DefaultTreeNodeChildren implements TreeNodeChildren { public List<TreeNode> children; @@ -42,6 +45,32 @@ } @Override + public Either<Error, TreeNode> addNewChildAt(int _pos, TreeNode _newChild) { + if (!boundaryCheck(_pos)) { + return DefaultEither.newA(NodeEditorError.INDEX_OUT_OF_BOUNDS); + } + List<TreeNode> newChildren = children.add(_pos, _newChild); + TreeNode newNode = new DefaultTreeNode(newChildren, attrs); + + return DefaultEither.newB(newNode); + } + + @Override + public Either<Error, TreeNode> addNewChildAndPutAttribtue(int pos, String key, ByteBuffer value) { + if (!boundaryCheck(pos)) { + return DefaultEither.newA(NodeEditorError.INDEX_OUT_OF_BOUNDS); + } + TreeNode node = new DefaultTreeNode(); + TreeNodeAttributes attribute = node.getAttributes(); + Either<Error,TreeNode> either = attribute.put(key, value); + if (either.isA()) + return DefaultEither.newA(PUT_ATTRIBUTE_ERROR); + TreeNode newTreeNode = either.b(); + return addNewChildAt(pos,newTreeNode); + } + + + @Override public Either<Error, TreeNode> deleteChildAt(int _pos) { if (!boundaryCheck(_pos)) { return DefaultEither.newA(NodeEditorError.INDEX_OUT_OF_BOUNDS); @@ -102,15 +131,4 @@ return DefaultEither.newB(Node); } - @Override - public Either<Error, TreeNode> addNewChildAt(int _pos, TreeNode _newChild) { - if (!boundaryCheck(_pos)) { - return DefaultEither.newA(NodeEditorError.INDEX_OUT_OF_BOUNDS); - } - List<TreeNode> newChildren = children.add(_pos, _newChild); - TreeNode newNode = new DefaultTreeNode(newChildren, attrs); - - return DefaultEither.newB(newNode); - } - }
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/transaction/node/Differencial/DifferencialTreeNode.java Sat Dec 31 03:30:14 2016 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/transaction/node/Differencial/DifferencialTreeNode.java Tue Jan 03 21:27:55 2017 +0900 @@ -48,7 +48,12 @@ } @Override + public int getHash() { + return this.getHash(); + } + + @Override public int compareTo(TreeNode o) { return this.hashCode() - o.hashCode(); } -} +} \ No newline at end of file
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/transaction/node/Differencial/DifferencialTreeNodeAttribute.java Sat Dec 31 03:30:14 2016 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/transaction/node/Differencial/DifferencialTreeNodeAttribute.java Tue Jan 03 21:27:55 2017 +0900 @@ -12,9 +12,7 @@ import java.util.List; import java.util.TreeMap; -/** - * Created by e115731 on 2016/12/15. - */ + public class DifferencialTreeNodeAttribute implements TreeNodeAttributes { private TreeMap<String, ByteBuffer> attrs;
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/transaction/node/Differencial/DifferencialTreeNodeChildren.java Sat Dec 31 03:30:14 2016 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/transaction/node/Differencial/DifferencialTreeNodeChildren.java Tue Jan 03 21:27:55 2017 +0900 @@ -3,15 +3,19 @@ import jp.ac.u_ryukyu.ie.cr.jungle.store.trasnformer.NodeEditorError; import jp.ac.u_ryukyu.ie.cr.jungle.transaction.node.TreeNode; +import jp.ac.u_ryukyu.ie.cr.jungle.transaction.node.TreeNodeAttributes; import jp.ac.u_ryukyu.ie.cr.jungle.transaction.node.TreeNodeChildren; import jp.ac.u_ryukyu.ie.cr.jungle.util.DefaultEither; import jp.ac.u_ryukyu.ie.cr.jungle.util.Either; import jp.ac.u_ryukyu.ie.cr.jungle.util.Error.DefaultError; import jp.ac.u_ryukyu.ie.cr.jungle.util.Error.Error; +import java.nio.ByteBuffer; import java.util.Iterator; import java.util.List; +import static jp.ac.u_ryukyu.ie.cr.jungle.util.Error.TreeNodeError.PUT_ATTRIBUTE_ERROR; + public class DifferencialTreeNodeChildren implements TreeNodeChildren { private List<TreeNode> children; @@ -76,18 +80,34 @@ if (move.equals("up") && pos != 0) { children.remove(pos); children.add((pos - 1), child); - } else if (move.equals("down") && pos < size - 1) { //sizeは0から始まるため -1する - children.remove(pos); - children.add((pos + 1), child); - } else { - return DefaultEither.newA(new DefaultError()); - } + } else + if (move.equals("down") && pos < size - 1) { //sizeは0から始まるため -1する + children.remove(pos); + children.add((pos + 1), child); + } else { + return DefaultEither.newA(new DefaultError()); + } return DefaultEither.newB(node); } @Override + public Either<Error, TreeNode> addNewChildAndPutAttribtue(int pos, String key, ByteBuffer value) { + if (!boundaryCheck(pos)) { + return DefaultEither.newA(NodeEditorError.INDEX_OUT_OF_BOUNDS); + } + TreeNode node = new DifferencialTreeNode(); + TreeNodeAttributes attribute = node.getAttributes(); + Either<Error, TreeNode> either = attribute.put(key, value); + if (either.isA()) + return DefaultEither.newA(PUT_ATTRIBUTE_ERROR); + TreeNode child = either.b(); + return addNewChildAt(pos, child); + + } + + @Override public Either<Error, TreeNode> at(int _pos) { - if (!boundaryCheck(_pos + 1) || _pos < 0 ) { + if (!boundaryCheck(_pos + 1) || _pos < 0) { return DefaultEither.newA(NodeEditorError.INDEX_OUT_OF_BOUNDS); } TreeNode n = children.get(_pos);
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/transaction/node/TreeNode.java Sat Dec 31 03:30:14 2016 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/transaction/node/TreeNode.java Tue Jan 03 21:27:55 2017 +0900 @@ -5,6 +5,8 @@ public interface TreeNode extends Comparable<TreeNode> { + + public TreeNodeChildren getChildren(); public TreeNodeAttributes getAttributes(); @@ -12,4 +14,6 @@ public TreeNode createNewNode(); public Either<Error, TreeNode> appendRootNode(); + + public int getHash(); }
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/transaction/node/TreeNodeChildren.java Sat Dec 31 03:30:14 2016 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/transaction/node/TreeNodeChildren.java Tue Jan 03 21:27:55 2017 +0900 @@ -4,6 +4,8 @@ import jp.ac.u_ryukyu.ie.cr.jungle.util.Either; import jp.ac.u_ryukyu.ie.cr.jungle.util.Error.Error; +import java.nio.ByteBuffer; + public interface TreeNodeChildren extends Children { public Either<Error,TreeNode> addNewChildAt(int pos); @@ -11,4 +13,5 @@ public Either<Error,TreeNode> addNewChildAt(int pos,TreeNode newChild); public Either<Error,TreeNode> replaceNode(int pos,TreeNode replacement); Either<Error,TreeNode> moveChild(int pos, String move); + Either<Error,TreeNode> addNewChildAndPutAttribtue(int pos, String key,ByteBuffer value); } \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/transaction/node/redBlackTree/BlackTreeNode.java Tue Jan 03 21:27:55 2017 +0900 @@ -0,0 +1,81 @@ +package jp.ac.u_ryukyu.ie.cr.jungle.transaction.node.redBlackTree; + +import jp.ac.u_ryukyu.ie.cr.jungle.data.list.List; +import jp.ac.u_ryukyu.ie.cr.jungle.data.treemap.TreeMap; +import jp.ac.u_ryukyu.ie.cr.jungle.transaction.node.TreeNode; +import jp.ac.u_ryukyu.ie.cr.jungle.transaction.node.TreeNodeAttributes; +import jp.ac.u_ryukyu.ie.cr.jungle.transaction.node.TreeNodeChildren; +import jp.ac.u_ryukyu.ie.cr.jungle.util.DefaultEither; +import jp.ac.u_ryukyu.ie.cr.jungle.util.Either; +import jp.ac.u_ryukyu.ie.cr.jungle.util.Error.Error; + +import java.nio.ByteBuffer; + +import static jp.ac.u_ryukyu.ie.cr.jungle.util.Error.TreeNodeError.NOT_USE_METHOD; + +public class BlackTreeNode extends ColorlessTreeNode { + private TreeMap<String, ByteBuffer> attrs; + private static final List<TreeNode> NIL_LIST = new List<>(); + + public BlackTreeNode(String balanceKey, ByteBuffer value) { + this(new TreeMap<>(), balanceKey, value, new EmptyTreeNode(), new EmptyTreeNode()); + } + + public BlackTreeNode(String balanceKey, ByteBuffer value, ColorlessTreeNode left, ColorlessTreeNode right) { + this(new TreeMap<>(), balanceKey, value, left, right); + } + + public BlackTreeNode(TreeMap<String, ByteBuffer> _attrs, String balanceKey, ByteBuffer value, ColorlessTreeNode left, ColorlessTreeNode right) { + super(balanceKey,value,left,right); + this.attrs = _attrs; + } + + @Override + public TreeNodeChildren getChildren() { + return new RedTreeNodeChildren(this, attrs); + } + + @Override + public ColorlessTreeNode createNode(ColorlessTreeNode newChild, ColorlessTreeNode left, ColorlessTreeNode right) { + return null; + } + + @Override + public TreeNodeAttributes getAttributes() { + return new RedBlackTreeNodeAttribute(left(), right(), attrs); + } + + @Override + public TreeNode createNewNode() { + return null;//new BlackTreeNode(); + } + + public TreeNode clone() { + return new BlackTreeNode(attrs, key(), value(), left(), right()); + } + + @Override + public Either<Error, TreeNode> appendRootNode() { + return DefaultEither.newA(NOT_USE_METHOD); + } + + @Override + public int compareTo(TreeNode o) { + return this.getHash() - o.getHash(); + } + + @Override + public int getHash() { + return value().hashCode(); + } + + @Override + public boolean isRed() { + return false; + } + + @Override + public boolean empty(){ + return false; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/transaction/node/redBlackTree/ColorlessTreeNode.java Tue Jan 03 21:27:55 2017 +0900 @@ -0,0 +1,60 @@ +package jp.ac.u_ryukyu.ie.cr.jungle.transaction.node.redBlackTree; + +import jp.ac.u_ryukyu.ie.cr.jungle.transaction.node.TreeNode; +import jp.ac.u_ryukyu.ie.cr.jungle.transaction.node.TreeNodeChildren; + +import java.nio.ByteBuffer; + +/** + * Created by e115731 on 2017/01/03. + */ +public abstract class ColorlessTreeNode implements TreeNode { + + private String balanceKey; + private ByteBuffer value; + private ColorlessTreeNode leftChild; + private ColorlessTreeNode rightChild; + + public ColorlessTreeNode (String balanceKey, ByteBuffer value, ColorlessTreeNode left, ColorlessTreeNode right) { + this.balanceKey = balanceKey; + this.value = value; + this.leftChild = left; + this.rightChild = right; + } + + public ColorlessTreeNode left() { + return leftChild; + }; + + public ColorlessTreeNode right() { + return rightChild; + }; + + public String key() { + return balanceKey; + } + + public ByteBuffer value() { + return value; + } + + @Override + public abstract TreeNodeChildren getChildren(); + + public abstract ColorlessTreeNode createNode(ColorlessTreeNode newChild, ColorlessTreeNode left, ColorlessTreeNode right); + + public abstract boolean isRed(); + + public abstract boolean empty(); + + public ColorlessTreeNode addNewChild(ColorlessTreeNode newChild) { + if (this.empty()) { + return createNode(newChild, leftChild,rightChild); + } + + // int compare = this.compareTo() + // if () + + return null; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/transaction/node/redBlackTree/EmptyTreeNode.java Tue Jan 03 21:27:55 2017 +0900 @@ -0,0 +1,61 @@ +package jp.ac.u_ryukyu.ie.cr.jungle.transaction.node.redBlackTree; + +import jp.ac.u_ryukyu.ie.cr.jungle.transaction.node.TreeNode; +import jp.ac.u_ryukyu.ie.cr.jungle.transaction.node.TreeNodeAttributes; +import jp.ac.u_ryukyu.ie.cr.jungle.transaction.node.TreeNodeChildren; +import jp.ac.u_ryukyu.ie.cr.jungle.util.Either; +import jp.ac.u_ryukyu.ie.cr.jungle.util.Error.Error; + + +public class EmptyTreeNode extends ColorlessTreeNode { + + public EmptyTreeNode() { + super(null, null, null, null); + } + + @Override + public TreeNodeChildren getChildren() { + return new RedTreeNodeChildren(this,null); + } + + @Override + public TreeNodeAttributes getAttributes() { + return null; //使わない + } + + @Override + public TreeNode createNewNode() { + return new EmptyTreeNode(); + } + + @Override + public Either<Error, TreeNode> appendRootNode() { + return null; + } + + @Override + public int getHash() { + return 0; + } + + @Override + public int compareTo(TreeNode o) { + return 0; + } + + @Override + public boolean isRed(){ + return false; + } + + @Override + public boolean empty(){ + return true; + } + @Override + public ColorlessTreeNode createNode(ColorlessTreeNode newChild, ColorlessTreeNode left, ColorlessTreeNode right) { + TreeNodeChildren children = newChild.getChildren(); + //children.addNewChildAt(); + return null;//new RedTreeNode(attrs, key, value, left, right); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/transaction/node/redBlackTree/RedBlackTreeNodeAttribute.java Tue Jan 03 21:27:55 2017 +0900 @@ -0,0 +1,54 @@ +package jp.ac.u_ryukyu.ie.cr.jungle.transaction.node.redBlackTree; + +import jp.ac.u_ryukyu.ie.cr.jungle.data.treemap.TreeMap; +import jp.ac.u_ryukyu.ie.cr.jungle.transaction.node.TreeNode; +import jp.ac.u_ryukyu.ie.cr.jungle.transaction.node.TreeNodeAttributes; +import jp.ac.u_ryukyu.ie.cr.jungle.util.Either; +import jp.ac.u_ryukyu.ie.cr.jungle.util.Error.Error; + +import java.nio.ByteBuffer; +import java.util.Iterator; +import java.util.List; + +/** + * Created by e115731 on 2017/01/03. + */ +public class RedBlackTreeNodeAttribute implements TreeNodeAttributes{ + public RedBlackTreeNodeAttribute(TreeNode leftChild, TreeNode rightChild, TreeMap<String, ByteBuffer> attrs) { + } + + @Override + public Either<Error, TreeNode> delete(String key) { + return null; + } + + @Override + public Either<Error, TreeNode> put(String key, ByteBuffer value) { + return null; + } + + @Override + public ByteBuffer get(String key) { + return null; + } + + @Override + public String getString(String key) { + return null; + } + + @Override + public Iterator<String> getKeys() { + return null; + } + + @Override + public boolean contain(String key) { + return false; + } + + @Override + public Iterator<String> getFilteringKey(List<String> filter) { + return null; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/transaction/node/redBlackTree/RedTreeNode.java Tue Jan 03 21:27:55 2017 +0900 @@ -0,0 +1,86 @@ +package jp.ac.u_ryukyu.ie.cr.jungle.transaction.node.redBlackTree; + +import jp.ac.u_ryukyu.ie.cr.jungle.data.list.List; +import jp.ac.u_ryukyu.ie.cr.jungle.data.treemap.TreeMap; +import jp.ac.u_ryukyu.ie.cr.jungle.transaction.node.TreeNode; +import jp.ac.u_ryukyu.ie.cr.jungle.transaction.node.TreeNodeAttributes; +import jp.ac.u_ryukyu.ie.cr.jungle.transaction.node.TreeNodeChildren; +import jp.ac.u_ryukyu.ie.cr.jungle.util.DefaultEither; +import jp.ac.u_ryukyu.ie.cr.jungle.util.Either; +import jp.ac.u_ryukyu.ie.cr.jungle.util.Error.Error; + +import java.nio.ByteBuffer; + +import static jp.ac.u_ryukyu.ie.cr.jungle.util.Error.TreeNodeError.NOT_USE_METHOD; + +public class RedTreeNode extends ColorlessTreeNode { + private TreeMap<String, ByteBuffer> attrs; + + private static final List<TreeNode> NIL_LIST = new List<>(); + + public RedTreeNode(String balanceKey, ByteBuffer value) { + this(new TreeMap<>(), balanceKey, value, new EmptyTreeNode(), new EmptyTreeNode()); + } + + public RedTreeNode(String balanceKey, ByteBuffer value, ColorlessTreeNode left, ColorlessTreeNode right) { + this(new TreeMap<>(), balanceKey, value, left, right); + } + + public RedTreeNode(TreeMap<String, ByteBuffer> _attrs, String balanceKey, ByteBuffer value, ColorlessTreeNode left, ColorlessTreeNode right) { + super(balanceKey, value, left, right); + this.attrs = _attrs; + } + + @Override + public TreeNodeChildren getChildren() { + return new RedTreeNodeChildren(this, attrs); + } + + @Override + public ColorlessTreeNode createNode(ColorlessTreeNode newChild, ColorlessTreeNode left, ColorlessTreeNode right) { + String key = newChild.key(); + ByteBuffer value = newChild.value(); + //newChild.getAttributes(). + return new RedTreeNode(attrs, key, value, left, right); + } + + @Override + public TreeNodeAttributes getAttributes() { + return new RedBlackTreeNodeAttribute(left(), right(), attrs); + } + + @Override + public TreeNode createNewNode() { + return null;//new BlackTreeNode(); + } + + public TreeNode clone() { + return new BlackTreeNode(attrs, key(), value(), left(), right()); + } + + @Override + public Either<Error, TreeNode> appendRootNode() { + return DefaultEither.newA(NOT_USE_METHOD); + } + + @Override + public int compareTo(TreeNode o) { + return this.getHash() - o.getHash(); + } + + @Override + public int getHash() { + return value().hashCode(); + } + + @Override + public boolean isRed() { + return true; + } + + @Override + public boolean empty(){ + return false; + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/transaction/node/redBlackTree/RedTreeNodeChildren.java Tue Jan 03 21:27:55 2017 +0900 @@ -0,0 +1,80 @@ +package jp.ac.u_ryukyu.ie.cr.jungle.transaction.node.redBlackTree; + +import jp.ac.u_ryukyu.ie.cr.jungle.data.treemap.TreeMap; +import jp.ac.u_ryukyu.ie.cr.jungle.transaction.node.TreeNode; +import jp.ac.u_ryukyu.ie.cr.jungle.transaction.node.TreeNodeChildren; +import jp.ac.u_ryukyu.ie.cr.jungle.util.DefaultEither; +import jp.ac.u_ryukyu.ie.cr.jungle.util.Either; +import jp.ac.u_ryukyu.ie.cr.jungle.util.Error.Error; + +import java.nio.ByteBuffer; +import java.util.Iterator; + +/** + * Created by e115731 on 2017/01/03. + */ +public class RedTreeNodeChildren implements TreeNodeChildren { + + private final ColorlessTreeNode node; + private final TreeMap<String, ByteBuffer> attrs; + + public RedTreeNodeChildren(ColorlessTreeNode node, TreeMap<String, ByteBuffer> attrs) { + this.node = node; + this.attrs = attrs; + } + + + /** + * 赤黒木ではノード単体の追加は行わない + * なので下2つのaddNewChildAtは使われない + * ここをなんとかしたかった + */ + @Override + public Either<Error, TreeNode> addNewChildAt(int pos) { + return null; + } + + @Override + public Either<Error, TreeNode> addNewChildAt(int pos, TreeNode newChild) { + return null; + } + + + @Override + public Either<Error, TreeNode> addNewChildAndPutAttribtue(int pos, String key, ByteBuffer value) { + ColorlessTreeNode newChild = new RedTreeNode(key,value); + ColorlessTreeNode newNode = node.addNewChild(newChild); + return DefaultEither.newB(newNode); + } + + + @Override + public Either<Error, TreeNode> deleteChildAt(int pos) { + return null; + } + + @Override + public Either<Error, TreeNode> replaceNode(int pos, TreeNode replacement) { + return null; + } + + @Override + public Either<Error, TreeNode> moveChild(int pos, String move) { + return null; + } + + @Override + public Either<Error, TreeNode> at(int pos) { + return null; + } + + @Override + public int size() { + return 0; + } + + @Override + public Iterator<TreeNode> iterator() { + return null; + } +}
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/traverser/DefaultTraverser.java Sat Dec 31 03:30:14 2016 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/traverser/DefaultTraverser.java Tue Jan 03 21:27:55 2017 +0900 @@ -77,6 +77,10 @@ return DefaultEither.newB(_goal(ch, pos)); } + if (r == Result.SPECIAL) { + return DefaultEither.newB(_goal(ch, -2)); + } + if (r == Result.BREAK) { break; }
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/traverser/Result.java Sat Dec 31 03:30:14 2016 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/traverser/Result.java Tue Jan 03 21:27:55 2017 +0900 @@ -7,7 +7,7 @@ public static final Result CONTINUE = new Result("CONTINUE"); public static final Result BREAK = new Result("BREAK"); public static final Result GOAL = new Result("GOAL"); - + public static final Result SPECIAL = new Result("SPECIAL"); private final String name; private Result(String _name)
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/traverser/Traverser.java Sat Dec 31 03:30:14 2016 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/traverser/Traverser.java Tue Jan 03 21:27:55 2017 +0900 @@ -7,6 +7,4 @@ public interface Traverser { public Either<Error,Traversal> traverse(final TreeNode _root,Evaluator _evaluator); - - }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/tree/RedBlackJungleTree.java Tue Jan 03 21:27:55 2017 +0900 @@ -0,0 +1,38 @@ +package jp.ac.u_ryukyu.ie.cr.jungle.tree; + +import jp.ac.u_ryukyu.ie.cr.jungle.persistent.ChangeListWriter; +import jp.ac.u_ryukyu.ie.cr.jungle.store.TreeContext; +import jp.ac.u_ryukyu.ie.cr.jungle.transaction.editor.jungleTreeEditor.JungleTreeEditor; +import jp.ac.u_ryukyu.ie.cr.jungle.transaction.editor.jungleTreeEditor.RedBlackJungleTreeEditor; +import jp.ac.u_ryukyu.ie.cr.jungle.transaction.editor.treeEditor.TreeEditor; +import jp.ac.u_ryukyu.ie.cr.jungle.transaction.manager.DefaultTransactionManager; +import jp.ac.u_ryukyu.ie.cr.jungle.transaction.manager.TransactionManager; +import jp.ac.u_ryukyu.ie.cr.jungle.transaction.node.TreeNode; + +import java.util.concurrent.atomic.AtomicReference; + +/** + * Created by e115731 on 2017/01/02. + */ +public class RedBlackJungleTree extends DefaultJungleTree { + + private final String balanceKey; + + public RedBlackJungleTree(TreeContext tc, String uuid, ChangeListWriter writer, TreeEditor editor, String balanceKey) { + super(tc, uuid, writer, editor); + this.balanceKey = balanceKey; + } + + @Override + public JungleTreeEditor getJungleTreeEditor() { + AtomicReference<TreeContext> repository = super.getRepository(); + TreeContext tc = repository.get(); + ChangeListWriter writer = super.getWriter(); + String uuid = super.getUuid(); + TreeEditor treeEditor = super.getTreeEditor(); + TransactionManager txManager = new DefaultTransactionManager(writer, tc, repository, uuid); + TreeNode root = tc.getRoot(); + return new RedBlackJungleTreeEditor(root, balanceKey, txManager, treeEditor); + } +} +
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/util/Error/JungleTreeError.java Sat Dec 31 03:30:14 2016 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/util/Error/JungleTreeError.java Tue Jan 03 21:27:55 2017 +0900 @@ -6,4 +6,5 @@ public class JungleTreeError { public static final Error INVALID_ARGUMENT = new DefaultError(); public static final Error APPEND_FAILD = new DefaultError(); + public static final Error NOT_USE_METHOD = new DefaultError(); }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/util/Error/TreeNodeError.java Tue Jan 03 21:27:55 2017 +0900 @@ -0,0 +1,7 @@ +package jp.ac.u_ryukyu.ie.cr.jungle.util.Error; + +public class TreeNodeError { + public static final Error NOT_USE_METHOD = new DefaultError(); + public static final Error CHILREN_ADD_ERROR = new DefaultError(); + public static final Error PUT_ATTRIBUTE_ERROR = new DefaultError(); +}
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/jungleNetwork/core/NetworkDefaultJungle.java Sat Dec 31 03:30:14 2016 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungleNetwork/core/NetworkDefaultJungle.java Tue Jan 03 21:27:55 2017 +0900 @@ -12,7 +12,7 @@ import jp.ac.u_ryukyu.ie.cr.jungle.store.logger.DefaultTreeOperationLog; import jp.ac.u_ryukyu.ie.cr.jungle.store.logger.TreeOperationLog; import jp.ac.u_ryukyu.ie.cr.jungle.store.operations.TreeOperation; -import jp.ac.u_ryukyu.ie.cr.jungle.transaction.DefaultTreeContext; +import jp.ac.u_ryukyu.ie.cr.jungle.transaction.context.DefaultTreeContext; import jp.ac.u_ryukyu.ie.cr.jungle.transaction.node.Default.DefaultTreeNode; import jp.ac.u_ryukyu.ie.cr.jungle.traverser.InterfaceTraverser; import jp.ac.u_ryukyu.ie.cr.jungleNetwork.transaction.NetworkDefaultJungleTree; @@ -88,6 +88,10 @@ return null;//未実装 } + @Override + public JungleTree createNewRedBlackTree(String name, String balanceKey) { + return null;//未実装 + } @Override public Iterator<String> getTreeNames() {
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/jungleNetwork/persistent/PersistentJungle.java Sat Dec 31 03:30:14 2016 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungleNetwork/persistent/PersistentJungle.java Tue Jan 03 21:27:55 2017 +0900 @@ -87,6 +87,11 @@ } @Override + public JungleTree createNewRedBlackTree(String name, String balanceKey) { + return null;//未実装 + } + + @Override public Iterator<String> getTreeNames() { Enumeration<String> treeNames = trees.keys(); return new Iterator<String>() {
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/jungleNetwork/persistent/PersistentJungleTreeEditor.java Sat Dec 31 03:30:14 2016 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungleNetwork/persistent/PersistentJungleTreeEditor.java Tue Jan 03 21:27:55 2017 +0900 @@ -79,6 +79,12 @@ } @Override + public Either<Error, JungleTreeEditor> addNewChildAndPutAttribute(NodePath path, int pos, String key, ByteBuffer value) { + AppendChildAndPutAttribute appendChildAndPutAttribute = new AppendChildAndPutAttribute(key,value,pos); + return _edit(path,appendChildAndPutAttribute); + } + + @Override public Either<Error, JungleTreeEditor> deleteChildAt(NodePath _path, int _pos) { DeleteChildAt deleteChildAt = new DeleteChildAt(_pos); return _edit(_path, deleteChildAt);
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/jungleNetwork/transaction/NetworkDefaultJungleTreeEditor.java Sat Dec 31 03:30:14 2016 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungleNetwork/transaction/NetworkDefaultJungleTreeEditor.java Tue Jan 03 21:27:55 2017 +0900 @@ -101,6 +101,12 @@ } @Override + public Either<Error, JungleTreeEditor> addNewChildAndPutAttribute(NodePath path, int pos, String key, ByteBuffer value) { + AppendChildAndPutAttribute appendChildAndPutAttribute = new AppendChildAndPutAttribute(key,value,pos); + return _edit(path,appendChildAndPutAttribute); + } + + @Override public Either<Error,JungleTreeEditor> deleteChildAt(NodePath _path, int _pos) { DeleteChildAt deleteChildAt = new DeleteChildAt(_pos);
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/jungleNetwork/transaction/NetworkTransactionManager.java Sat Dec 31 03:30:14 2016 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungleNetwork/transaction/NetworkTransactionManager.java Tue Jan 03 21:27:55 2017 +0900 @@ -7,7 +7,7 @@ import jp.ac.u_ryukyu.ie.cr.jungle.store.TreeContext; import jp.ac.u_ryukyu.ie.cr.jungle.store.logger.TreeOperationLog; import jp.ac.u_ryukyu.ie.cr.jungle.store.operations.TreeOperation; -import jp.ac.u_ryukyu.ie.cr.jungle.transaction.DefaultTreeContext; +import jp.ac.u_ryukyu.ie.cr.jungle.transaction.context.DefaultTreeContext; import jp.ac.u_ryukyu.ie.cr.jungle.transaction.manager.TransactionManager; import jp.ac.u_ryukyu.ie.cr.jungle.transaction.node.TreeNode; import jp.ac.u_ryukyu.ie.cr.jungle.traverser.InterfaceTraverser;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/jp/ac/u_ryukyu/ie/cr/jungle/core/nodeeditor/AppendChildAndPutAttributeTest.java Tue Jan 03 21:27:55 2017 +0900 @@ -0,0 +1,47 @@ +package jp.ac.u_ryukyu.ie.cr.jungle.core.nodeeditor; + +import jp.ac.u_ryukyu.ie.cr.jungle.DefaultJungle; +import jp.ac.u_ryukyu.ie.cr.jungle.Jungle; +import jp.ac.u_ryukyu.ie.cr.jungle.core.Attributes; +import jp.ac.u_ryukyu.ie.cr.jungle.core.Children; +import jp.ac.u_ryukyu.ie.cr.jungle.store.nodepath.DefaultNodePath; +import jp.ac.u_ryukyu.ie.cr.jungle.store.nodepath.NodePath; +import jp.ac.u_ryukyu.ie.cr.jungle.transaction.editor.jungleTreeEditor.JungleTreeEditor; +import jp.ac.u_ryukyu.ie.cr.jungle.transaction.node.TreeNode; +import jp.ac.u_ryukyu.ie.cr.jungle.traverser.DefaultTraverser; +import jp.ac.u_ryukyu.ie.cr.jungle.tree.JungleTree; +import jp.ac.u_ryukyu.ie.cr.jungle.util.Either; +import jp.ac.u_ryukyu.ie.cr.jungle.util.Error.Error; +import junit.framework.Assert; +import org.junit.Test; + +import java.nio.ByteBuffer; + +/** + * Created by e115731 on 2017/01/03. + */ +public class AppendChildAndPutAttributeTest { + @Test + public void AppendChildAndPutAttribute() { + Jungle jungle = new DefaultJungle(null, "hogehoge", new DefaultTraverser()); + jungle.createNewTree("tree"); + JungleTree tree = jungle.getTreeByName("tree"); + JungleTreeEditor editor = tree.getJungleTreeEditor(); + + NodePath path = new DefaultNodePath(); + String key = "key"; + ByteBuffer value = ByteBuffer.wrap("value".getBytes()); + Either<Error, JungleTreeEditor> either = editor.addNewChildAndPutAttribute(path,0,key,value); + Assert.assertTrue(either.isB()); + JungleTreeEditor newTreeEditor = either.b(); + Assert.assertTrue(newTreeEditor.success().isB()); + TreeNode newRoot = tree.getRootNode(); + Children children = newRoot.getChildren(); + Either<Error,TreeNode> childrenEither = children.at(0); + Assert.assertFalse(childrenEither.isA()); + TreeNode child = childrenEither.b(); + Attributes attribute = child.getAttributes(); + ByteBuffer childHaveAttribute = attribute.get("key"); + Assert.assertEquals(value,childHaveAttribute); + } +} \ No newline at end of file
--- a/src/test/java/jp/ac/u_ryukyu/ie/cr/jungle/core/treeeditor/Difference/DifferencialJungleTreeEditorTest.java Sat Dec 31 03:30:14 2016 +0900 +++ b/src/test/java/jp/ac/u_ryukyu/ie/cr/jungle/core/treeeditor/Difference/DifferencialJungleTreeEditorTest.java Tue Jan 03 21:27:55 2017 +0900 @@ -39,6 +39,7 @@ JungleTreeEditor editor4 = either3.b(); Either<Error, JungleTreeEditor> either4 = editor4.success(); Assert.assertFalse(either4.isA()); + TreeNode root = tree.getRootNode(); TreeNodeChildren children = root.getChildren(); int expectChildCount = 1;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/jp/ac/u_ryukyu/ie/cr/jungle/core/treeeditor/RedBlack/RedBlackTreeEditorTest.java Tue Jan 03 21:27:55 2017 +0900 @@ -0,0 +1,24 @@ +package jp.ac.u_ryukyu.ie.cr.jungle.core.treeeditor.RedBlack; + +import jp.ac.u_ryukyu.ie.cr.jungle.DefaultJungle; +import jp.ac.u_ryukyu.ie.cr.jungle.Jungle; +import jp.ac.u_ryukyu.ie.cr.jungle.store.nodepath.DefaultNodePath; +import jp.ac.u_ryukyu.ie.cr.jungle.store.nodepath.NodePath; +import jp.ac.u_ryukyu.ie.cr.jungle.transaction.editor.jungleTreeEditor.JungleTreeEditor; +import jp.ac.u_ryukyu.ie.cr.jungle.traverser.DefaultTraverser; +import jp.ac.u_ryukyu.ie.cr.jungle.tree.JungleTree; +import org.junit.Test; + +public class RedBlackTreeEditorTest { + @Test + public void RedBlackTreeEditor() { + Jungle jungle = new DefaultJungle(null, "hogehoge", new DefaultTraverser()); + JungleTree tree = jungle.createNewRedBlackTree("TreeName", "balanceKey"); + JungleTreeEditor editor = tree.getJungleTreeEditor(); + NodePath path = new DefaultNodePath(); + //Either<Error, JungleTreeEditor> either = editor.addNewChildAt(path, 0); + // Assert.assertFalse(either.isA()); + // editor = either.b(); + // editor.addNewChildAt(path,0); + } +}