Mercurial > hg > Members > shoshi > jungle > jungle-core
changeset 97:a1e20a440ddd
add BruteForceTraverser
author | one |
---|---|
date | Mon, 08 Sep 2014 17:03:08 +0900 |
parents | bd82c20a6da0 |
children | 95000ff9064d |
files | src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/TreeNode.java src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/transaction/DefaultTreeNode.java src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/transaction/DefaultTreeNodeAttribute.java src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/transaction/DefaultTreeNodeChildren.java src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/traverser/BruteForceTraverser.java |
diffstat | 5 files changed, 61 insertions(+), 40 deletions(-) [+] |
line wrap: on
line diff
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/TreeNode.java Sat Sep 06 15:22:46 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/TreeNode.java Mon Sep 08 17:03:08 2014 +0900 @@ -12,8 +12,4 @@ public TreeNode createNewNode(); - public OperationLog getLog(); - - public void putLog(OperationLog _log); - }
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/transaction/DefaultTreeNode.java Sat Sep 06 15:22:46 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/transaction/DefaultTreeNode.java Mon Sep 08 17:03:08 2014 +0900 @@ -21,25 +21,13 @@ public DefaultTreeNode() { - this(NIL_LIST,NIL_MAP,new DefaultOperationLog()); + this(NIL_LIST,NIL_MAP); } public DefaultTreeNode(List<TreeNode> _children,TreeMap<String,ByteBuffer> _attrs) { - this(_children, _attrs, new DefaultOperationLog()); - } - - public DefaultTreeNode(TreeNode _node, OperationLog _log) - { - this(_node.getChildren().getChildrenAsRawList(), _node.getAttributes().getAttributesAsRawMap(), _log); - } - - - - public DefaultTreeNode(List<TreeNode> _children,TreeMap<String,ByteBuffer> _attrs, OperationLog _log){ attrs = _attrs; children = _children; - log = _log; } @Override @@ -74,17 +62,5 @@ { return new DefaultTreeNode(children,attrs); } - - @Override - public OperationLog getLog() { - OperationLog _log = log; - log = new DefaultOperationLog(); - return _log; - } - - @Override - public void putLog(OperationLog _log){ - log = _log; - } }
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/transaction/DefaultTreeNodeAttribute.java Sat Sep 06 15:22:46 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/transaction/DefaultTreeNodeAttribute.java Mon Sep 08 17:03:08 2014 +0900 @@ -53,9 +53,7 @@ } TreeMap<String,ByteBuffer> newMap = attrs.delete(_key); - - OperationLog op = new DefaultOperationLog();; - TreeNode newNode = new DefaultTreeNode(children,newMap,op.add(new DeleteAttributeOperation(_key))); + TreeNode newNode = new DefaultTreeNode(children,newMap); return DefaultEither.newB(newNode); } @@ -71,8 +69,7 @@ //TreeMap<String,ByteBuffer> raw = attrs.getAttributesAsRawMap(); TreeMap<String,ByteBuffer> newMap = attrs.set(_key,_value); - TreeNode newNode = new DefaultTreeNode(children,newMap,log.add(new PutAttributeOperation(_key,_value))); - + TreeNode newNode = new DefaultTreeNode(children,newMap); return DefaultEither.newB(newNode); }
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/transaction/DefaultTreeNodeChildren.java Sat Sep 06 15:22:46 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/transaction/DefaultTreeNodeChildren.java Mon Sep 08 17:03:08 2014 +0900 @@ -61,9 +61,7 @@ P2<List<TreeNode>,List<TreeNode>> split = children.splitAt(_pos); List<TreeNode> newChildren = split._1().snoc(new DefaultTreeNode()).append(split._2()); - OperationLog op = new DefaultOperationLog(); - TreeNode newNode = new DefaultTreeNode(newChildren,attrs,op.add(new AppendChildAtOperation(_pos))); - + TreeNode newNode = new DefaultTreeNode(newChildren,attrs); return DefaultEither.newB(newNode); } @@ -76,9 +74,7 @@ P2<List<TreeNode>,List<TreeNode>> split = children.splitAt(_pos); List<TreeNode> newChildren = split._1().append(split._2().tail()); - - OperationLog op = new DefaultOperationLog(); - TreeNode newNode = new DefaultTreeNode(newChildren,attrs,op.add(new DeleteChildAtOperation(_pos))); + TreeNode newNode = new DefaultTreeNode(newChildren,attrs); return DefaultEither.newB(newNode); }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/traverser/BruteForceTraverser.java Mon Sep 08 17:03:08 2014 +0900 @@ -0,0 +1,56 @@ +package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.traverser; + +import fj.data.List; +import fj.data.TreeMap; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.core.Children; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.NodePath; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.DefaultNodePath; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNode; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Pair; + +public class BruteForceTraverser { + List<Pair<NodePath,TreeNode>> pathNodes; + TreeMap<String,TreeNode> nodeIndex; + TreeMap<String,String> attributeIndex; + + BruteForceTraverser(TreeNode _root){ + pathNodes = this.traverse(_root,new DefaultNodePath(),-1); + } + + public List<Pair<NodePath,TreeNode>> traverse(TreeNode _node ,NodePath _path ,int _pos){ + + Children children = _node.getChildren(); + List<Pair<NodePath,TreeNode>> list = List.nil(); + int pathCount = _pos; + if(children.size() == 0){ + list = list.cons(new Pair<NodePath,TreeNode>(_path.add(_pos),_node)); + return list; + } + + for(TreeNode child : children){ + list = list.append(traverse(child,_path,pathCount)); + pathCount++; + } + + list = list.cons(new Pair<NodePath,TreeNode>(_path.add(_pos),_node)); + return list; + } + + public List<Pair<NodePath,TreeNode>> search(String _key, String _Attribute){ + List<Pair<NodePath,TreeNode>> pathNode = List.nil(); + for(Pair<NodePath,TreeNode> searchNode : pathNodes){ + if(searchNode.right().getAttributes().get(_key).equals(_Attribute)) + pathNode = pathNode.cons(searchNode); + } + return pathNode; + } + + public int count(String _key, String _attribute){ + return this.search(_key,_attribute).length(); + } + + public List<Pair<NodePath,TreeNode>> distinct(String _key ,String... _attribute){ + return null; + } + +}