Mercurial > hg > Database > jungle-sharp
changeset 28:9588ad364fdd
Last commit before change.
line wrap: on
line diff
--- a/Main/jungle-main/DefaultJungle.cs Fri Dec 16 00:25:03 2016 +0900 +++ b/Main/jungle-main/DefaultJungle.cs Wed Jan 18 19:53:29 2017 +0900 @@ -10,48 +10,33 @@ private string uuid; private TreeEditor editor; - public void Start(){ - DefaultJungle j = new DefaultJungle(null, "hoge", new DefaultTreeEditor(new DefaultTraverser())); - JungleTree t = j.createNewTree ("fuga"); - - JungleTreeEditor e1 = t.getTreeEditor (); - - DefaultNodePath root = new DefaultNodePath (); - Either<Error, JungleTreeEditor> either = e1.addNewChildAt (root, 0); - e1 = either.b(); - either = e1.addNewChildAt (root.add (0), 0); - e1 = either.b (); - e1.commit (); - } - public DefaultJungle(Journal journal, string uuid, TreeEditor editor){ this.journal = new NullJournal(); - this.trees = new TreeMap <string, JungleTree>(); - this.uuid = uuid; - this.editor = editor; + this.trees = new TreeMap <string, JungleTree>(); + this.uuid = uuid; + this.editor = editor; } public JungleTree getTreeByName(string name) { - JungleTree jungle_tree = trees.get(name); if (jungle_tree != null) { return jungle_tree; } else { - Debug.Log ("そのTreeは無いようですね。"); + Debug.Log ("The Tree Name does not exist."); return null; } } public JungleTree createNewTree(string name) { - ChangeList list = new InnerChangeList(uuid,name); - DefaultTreeNode root = new DefaultTreeNode (); + ChangeList list = new InnerChangeList(uuid, name); + DefaultTreeNode root = new DefaultTreeNode (); InterfaceTraverser traverser = new InterfaceTraverser (root, true); - TreeContext tc = new DefaultTreeContext (root, null, list, uuid, name, 0, traverser); - JungleTree newTree = new DefaultJungleTree (tc, uuid, journal.getWriter (), editor); + TreeContext tc = new DefaultTreeContext (root, null, list, uuid, name, 0, traverser); + JungleTree newTree = new DefaultJungleTree (tc, uuid, journal.getWriter (), editor); if (newTree != null) { trees = trees.put (name, newTree); } else { - Debug.Log ("こんばんは、nullです。"); + Debug.Log ("The Tree Name already exist."); } return newTree; } @@ -61,7 +46,6 @@ string uuid; string name; - IEnumerator IEnumerable.GetEnumerator() { return this.GetEnumerator();
--- a/Main/jungle-main/JungleTreeEditor.cs Fri Dec 16 00:25:03 2016 +0900 +++ b/Main/jungle-main/JungleTreeEditor.cs Wed Jan 18 19:53:29 2017 +0900 @@ -4,9 +4,10 @@ Either<Error,JungleTreeEditor> addNewChildAt(NodePath path,int pos); Either<Error,JungleTreeEditor> deleteChildAt(NodePath path,int pos); Either<Error,JungleTreeEditor> putAttribute(NodePath path,string key, byte[] value); + // add Method put Attribute (path, T?); Either<Error,JungleTreeEditor> deleteAttribute(NodePath path,string key); Either<Error, JungleTreeEditor> replaceNewRootNode(); - Either<Error,JungleTreeEditor> edit(NodePath path,NodeEditor editor); + Either<Error,JungleTreeEditor> edit(NodePath path, NodeEditor editor); Either<Error,JungleTreeEditor> commit(); Either<Error,JungleTreeEditor> flushSuccess();
--- a/Main/jungle-main/data/list/List.cs Fri Dec 16 00:25:03 2016 +0900 +++ b/Main/jungle-main/data/list/List.cs Wed Jan 18 19:53:29 2017 +0900 @@ -1,121 +1,123 @@ -using UnityEngine; -using System.Collections; -using System.Collections.Generic; -using System; - -public class List<T> : IEnumerable<T> { - private readonly Node<T> head; - - public List() { - this.head = new headNode<T>(); - } - - // T...はC#だとparamsらしい 可変引数型というみたいだ - public List(params T[] attributes) { - List<T> list = new List<T> (); - foreach (T attribute_local in attributes) { - list = list.addLast (attribute_local); - } - } - - private List(Node<T> head) { - this.head = head; - } - - public Node<T> getHead() { - return head; - } - - public List<T> add(int num, T attribute) { - Node<T> newHead = head.add(0, num, attribute); - if (newHead == null) - return this; - return new List<T>(newHead); - } - - public List<T> addLast(T attribute) { - Node<T> newHead = head.addLast(attribute); - return new List<T>(newHead); - } - - - public T index(int num) { - int count = 0; - Node<T> currentNode = head.getNext(); - while (currentNode != null) { - if (count == num) { - return currentNode.getAttribute (); - } - currentNode = currentNode.getNext(); - count++; - } - return default(T); - } - - public IEnumerator<T> iterator() { - Node<T> currentNode = head.getNext(); - int count = 0; - int len = currentNode.length(); - while (len != count) { - yield return (T)currentNode.getAttribute(); - currentNode = currentNode.getNext (); - count++; - } - } - - IEnumerator IEnumerable.GetEnumerator() - { - return this.GetEnumerator(); - } - - public IEnumerator<T> GetEnumerator() - { - return iterator (); - } - - - public List<T> delete(int num) { - Node<T> newNode = head.delete(0, num); - if (newNode == null) - return this; - return new List<T>(newNode); - } - - public List<T> replace(int num, T attribute) { - Node<T> newHead = head.replaceNode(0, num, attribute); - if (newHead == null) - return this; - return new List<T>(newHead); - } - - public T tail() { - return index(length() - 1); - } - - // java code head. - public T headList() { - return index(0); - } - - public List<T> deleteLast() { - return delete(head.length() - 1); - } - - public List<T> deleteHead() { - return delete(0); - } - - public int length() { - return head.length(); - } - - public List<T> append(List<T> list) { - IEnumerator<T> iterator = list.iterator(); - List<T> newList = this; - while (iterator.MoveNext()) { - T attribute = iterator.Current; - newList = newList.addLast(attribute); - } - return newList; - } -} +using UnityEngine; +using System.Collections; +using System.Collections.Generic; +using System; + +namespace JungleDB { + public class List<T> : IEnumerable<T> { + private readonly Node<T> head; + + public List() { + this.head = new headNode<T>(); + } + + // T...はC#だとparamsらしい 可変引数型というみたいだ + public List(params T[] attributes) { + List<T> list = new List<T> (); + foreach (T attribute_local in attributes) { + list = list.addLast (attribute_local); + } + } + + private List(Node<T> head) { + this.head = head; + } + + public Node<T> getHead() { + return head; + } + + public List<T> add(int num, T attribute) { + Node<T> newHead = head.add(0, num, attribute); + if (newHead == null) + return this; + return new List<T>(newHead); + } + + public List<T> addLast(T attribute) { + Node<T> newHead = head.addLast(attribute); + return new List<T>(newHead); + } + + + public T index(int num) { + int count = 0; + Node<T> currentNode = head.getNext(); + while (currentNode != null) { + if (count == num) { + return currentNode.getAttribute (); + } + currentNode = currentNode.getNext(); + count++; + } + return default(T); + } + + public IEnumerator<T> iterator() { + Node<T> currentNode = head.getNext(); + int count = 0; + int len = currentNode.length(); + while (len != count) { + yield return (T)currentNode.getAttribute(); + currentNode = currentNode.getNext (); + count++; + } + } + + IEnumerator IEnumerable.GetEnumerator() + { + return this.GetEnumerator(); + } + + public IEnumerator<T> GetEnumerator() + { + return iterator (); + } + + + public List<T> delete(int num) { + Node<T> newNode = head.delete(0, num); + if (newNode == null) + return this; + return new List<T>(newNode); + } + + public List<T> replace(int num, T attribute) { + Node<T> newHead = head.replaceNode(0, num, attribute); + if (newHead == null) + return this; + return new List<T>(newHead); + } + + public T tail() { + return index(length() - 1); + } + + // java code head. + public T headList() { + return index(0); + } + + public List<T> deleteLast() { + return delete(head.length() - 1); + } + + public List<T> deleteHead() { + return delete(0); + } + + public int length() { + return head.length(); + } + + public List<T> append(List<T> list) { + IEnumerator<T> iterator = list.iterator(); + List<T> newList = this; + while (iterator.MoveNext()) { + T attribute = iterator.Current; + newList = newList.addLast(attribute); + } + return newList; + } + } +}
--- a/Main/jungle-main/data/treemap/TreeMap.cs Fri Dec 16 00:25:03 2016 +0900 +++ b/Main/jungle-main/data/treemap/TreeMap.cs Wed Jan 18 19:53:29 2017 +0900 @@ -76,10 +76,10 @@ Debug.Log ("-----------------------------------"); } - public class iterators<K> : IEnumerator<K> { - Stack<TreeMapNode<K,V>> nodeStack = new Stack<TreeMapNode<K,V>>(); - TreeMapNode<K,V> currentNode = new TreeMap<K,V>().getRoot(); - public List<K> appLines { get; set; } + public class iterators<T> : IEnumerator<T> { + Stack<TreeMapNode<T,V>> nodeStack = new Stack<TreeMapNode<T,V>>(); + TreeMapNode<T,V> currentNode = new TreeMap<T,V>().getRoot(); + public List<T> appLines { get; set; } private int position; @@ -88,9 +88,9 @@ } - public K Current{ + public T Current{ get { - K key = currentNode.getKey (); + T key = currentNode.getKey (); if (currentNode.lefts ().isNotEmpty ()) { nodeStack.Push (currentNode); currentNode = currentNode.lefts (); @@ -118,11 +118,11 @@ } public void Dispose() { - ((IEnumerator<K>)this.appLines).Dispose (); + ((IEnumerator<T>)this.appLines).Dispose (); } public void Reset() { - ((IEnumerator<K>)this.appLines).Reset(); + ((IEnumerator<T>)this.appLines).Reset(); } }
--- a/Main/jungle-main/store/impl/DefaultNodePath.cs Fri Dec 16 00:25:03 2016 +0900 +++ b/Main/jungle-main/store/impl/DefaultNodePath.cs Wed Jan 18 19:53:29 2017 +0900 @@ -2,87 +2,87 @@ using System.Collections.Generic; using System.Collections; -public class DefaultNodePath : NodePath { - private List<int> path = new List<int>(); - - IEnumerator IEnumerable.GetEnumerator() - { - // call the generic version of the method - return this.GetEnumerator(); - } +namespace JungleDB { + public class DefaultNodePath : NodePath { + private List<int> path = new List<int>(); - public IEnumerator<int> GetEnumerator() - { - return path.iterator (); - } + IEnumerator IEnumerable.GetEnumerator() + { + // call the generic version of the method + return this.GetEnumerator(); + } - public DefaultNodePath() { - path = new List<int> ().addLast (-1); - } + public IEnumerator<int> GetEnumerator() + { + return path.iterator (); + } + + public DefaultNodePath() { + path = new List<int> ().addLast (-1); + } - private DefaultNodePath(List<int> path) { - this.path = path; - } + private DefaultNodePath(List<int> path) { + this.path = path; + } - /// <summary> - /// Listに追加します。 - /// path = path.add(0)を2回する - /// path = path.add(0).add(0)する - /// これは同じ - /// </summary> - /// <param name="pos">Position.</param> + /// <summary> + /// Listに追加します。 + /// path = path.add(0)を2回する + /// path = path.add(0).add(0)する + /// これは同じ + /// </summary> + /// <param name="pos">Position.</param> - public NodePath add(int pos) { - List<int> newPath = path.addLast(pos); - return new DefaultNodePath(newPath); - } + public NodePath add(int pos) { + List<int> newPath = path.addLast(pos); + return new DefaultNodePath(newPath); + } - public Pair<int, NodePath> pop() { - int head = path.headList(); - List<int> tail = path.deleteHead(); - return new Pair<int, NodePath>(head, new DefaultNodePath(tail)); - } + public Pair<int, NodePath> pop() { + int head = path.headList(); + List<int> tail = path.deleteHead(); + return new Pair<int, NodePath>(head, new DefaultNodePath(tail)); + } - public Pair<int, NodePath> last() { - int last = path.headList(); - List<int> list = path.deleteHead(); - return new Pair<int, NodePath>(last, new DefaultNodePath(list)); - } + public Pair<int, NodePath> last() { + int last = path.headList(); + List<int> list = path.deleteHead(); + return new Pair<int, NodePath>(last, new DefaultNodePath(list)); + } - public override string ToString() { - string s = "List <"; - int list_count = this.path.length(); - int count = 0; - foreach(var i in this.path) { - if (count != list_count -1){ - s += i.ToString() + ","; - } else { - s += i.ToString(); + public override string ToString() { + string s = "List <"; + int list_count = this.path.length(); + int count = 0; + foreach(var i in this.path) { + if (count != list_count -1){ + s += i.ToString() + ","; + } else { + s += i.ToString(); + } + count++; } - count++; + return s + ">"; } - return s + ">"; - } - public int size() { - return path.length(); - } + public int size() { + return path.length(); + } - public NodePath tail() { - List<int> tail = path.deleteLast (); - return new DefaultNodePath (tail); - } + public NodePath tail() { + List<int> tail = path.deleteLast (); + return new DefaultNodePath (tail); + } - public List<DefaultNodePath> inits() { - List<DefaultNodePath> paths = new List<DefaultNodePath> (); - List<int> coursePath = new List<int> (); - foreach (int tmpPath in path) { - List<int> tmp = coursePath.addLast (tmpPath); - paths = paths.addLast (new DefaultNodePath (tmp)); - coursePath = tmp; + public List<DefaultNodePath> inits() { + List<DefaultNodePath> paths = new List<DefaultNodePath> (); + List<int> coursePath = new List<int> (); + foreach (int tmpPath in path) { + List<int> tmp = coursePath.addLast (tmpPath); + paths = paths.addLast (new DefaultNodePath (tmp)); + coursePath = tmp; + } + return paths; } - return paths; } - - -} +} \ No newline at end of file
--- a/Main/jungle-main/store/impl/DefaultTreeEditor.cs Fri Dec 16 00:25:03 2016 +0900 +++ b/Main/jungle-main/store/impl/DefaultTreeEditor.cs Wed Jan 18 19:53:29 2017 +0900 @@ -5,6 +5,7 @@ namespace JungleDB { public class DefaultTreeEditor : TreeEditor { private Traverser traverser; + public DefaultTreeEditor(Traverser traverser){ this.traverser = traverser; }
--- a/Main/jungle-main/store/impl/logger/LoggingChildren.cs Fri Dec 16 00:25:03 2016 +0900 +++ b/Main/jungle-main/store/impl/logger/LoggingChildren.cs Wed Jan 18 19:53:29 2017 +0900 @@ -33,7 +33,6 @@ public Either<Error,LoggingNode> addNewChildAt(int _pos) { - Debug.Log ("in addNewChild"); NodeOperation addNewChildAt = new AppendChildAtOperation(_pos); return edit(addNewChildAt); }
--- a/Main/jungle-main/store/impl/logger/LoggingNode.cs Fri Dec 16 00:25:03 2016 +0900 +++ b/Main/jungle-main/store/impl/logger/LoggingNode.cs Wed Jan 18 19:53:29 2017 +0900 @@ -24,7 +24,6 @@ public LoggingChildren getChildren() { - Debug.Log ("in gtChildren"); return new LoggingChildren(wrap,log); }
--- a/Main/jungle-main/transaction/DefaultJungleTreeEditor.cs Fri Dec 16 00:25:03 2016 +0900 +++ b/Main/jungle-main/transaction/DefaultJungleTreeEditor.cs Wed Jan 18 19:53:29 2017 +0900 @@ -8,6 +8,7 @@ private TreeNode root; private TreeEditor editor; private TreeOperationLog log; + private NodePath prevPath; public DefaultJungleTreeEditor(TreeNode _root,TransactionManager _txManager,TreeEditor _editor) : this(_root, _txManager, _editor, new DefaultTreeOperationLog()) @@ -26,7 +27,7 @@ - private Either<Error,JungleTreeEditor> _edit(NodePath _path,NodeEditor _e) + private Either<Error,JungleTreeEditor> _edit(NodePath _path, NodeEditor _e) { Either<Error, LoggingNode> either = editor.edit (root, _path, _e); if (either.isA ()) { @@ -78,11 +79,7 @@ public Either<Error,JungleTreeEditor> edit(NodePath _path,NodeEditor _editor) { return _edit(_path,_editor); } - - /// <summary> - /// Treeを変更したあとSuccess(push)を行う - /// </summary> - + public Either<Error,JungleTreeEditor> commit() { Either<Error,TransactionManager> either = this.txManager.commit(this.root, this.log); // このlogをサーバにpushする?
--- a/Main/jungle-main/transaction/DefaultTreeNodeAttribute.cs Fri Dec 16 00:25:03 2016 +0900 +++ b/Main/jungle-main/transaction/DefaultTreeNodeAttribute.cs Wed Jan 18 19:53:29 2017 +0900 @@ -10,7 +10,7 @@ public TreeMap<string, byte[]> attrs; public DefaultTreeNodeAttribute(List<TreeNode> _children, TreeMap<string, byte[]> _attrs){ - children = _children; // null? + children = _children; attrs = _attrs; } @@ -45,27 +45,19 @@ } public byte[] get(string _key) { - if (_key == null) { + if (_key == null) return new byte[1]{0}; - } - byte[] op = attrs.get(_key); //null - if (op != null) { + + byte[] op = attrs.get(_key); + if (op != null) return op; - } return new byte[1]{0}; } - public string getString(string key, Encoding enc) { - char[] attribute = key.ToCharArray(); - if (attribute != null){ - return new string(attribute); - } - return null; + public string getString(string key) { + return Encoding.UTF8.GetString (attrs.get (key)); } - public string getString(string key) { - return null; - } public IEnumerator<string> getKeys(){ return attrs.keys (); }
--- a/Main/jungle-main/transaction/DefaultTreeNodeChildren.cs Fri Dec 16 00:25:03 2016 +0900 +++ b/Main/jungle-main/transaction/DefaultTreeNodeChildren.cs Wed Jan 18 19:53:29 2017 +0900 @@ -4,8 +4,8 @@ namespace JungleDB { public class DefaultTreeNodeChildren : TreeNodeChildren { - public List<TreeNode> children; - public TreeMap<string, byte[]> attrs; + private List<TreeNode> children; + private TreeMap<string, byte[]> attrs; public DefaultTreeNodeChildren(List<TreeNode> _children, TreeMap<string, byte[]> _attrs){ children = _children;
--- a/Main/jungle-main/traverser/DefaultTraverser.cs Fri Dec 16 00:25:03 2016 +0900 +++ b/Main/jungle-main/traverser/DefaultTraverser.cs Wed Jan 18 19:53:29 2017 +0900 @@ -117,11 +117,11 @@ public class InnerChildren : Children{ TreeNode root; - Evaluator evaluator; + // Evaluator evaluator; public InnerChildren(TreeNode _root, Evaluator _evaluator){ this.root = _root; - this.evaluator = _evaluator; + // this.evaluator = _evaluator; } public IEnumerator<TreeNode> iterator() {
--- a/Main/jungle-main/traverser/InterfaceTraverser.cs Fri Dec 16 00:25:03 2016 +0900 +++ b/Main/jungle-main/traverser/InterfaceTraverser.cs Wed Jan 18 19:53:29 2017 +0900 @@ -1,11 +1,11 @@ namespace JungleDB { public class InterfaceTraverser { - TreeNode root; + // TreeNode root; TreeMap<string, TreeMap<string, List<TreeNode>>> indexList; ParentIndex parentIndex; - bool parentUpdateFlag; - bool useIndex; + // bool parentUpdateFlag; + // bool useIndex; public InterfaceTraverser(TreeNode root, bool indexFlag) : this (root, new TreeMap<string, TreeMap<string, List<TreeNode>>> (), new ParentIndex (), indexFlag) @@ -14,14 +14,14 @@ public InterfaceTraverser(TreeNode root, TreeMap<string, TreeMap<string, List<TreeNode>>> index, ParentIndex parentIndex, bool useIndex) { - this.root = root; + // this.root = root; this.indexList = index; this.parentIndex = parentIndex; - if (parentIndex.isEmpty()) - parentUpdateFlag = true; - else - parentUpdateFlag = false; - this.useIndex = useIndex; +// if (parentIndex.isEmpty()) +// //parentUpdateFlag = true; +// else +// //parentUpdateFlag = false; +// // this.useIndex = useIndex; } public TreeMap<string, TreeMap<string, List<TreeNode>>> getIndex() { @@ -29,7 +29,7 @@ } public void commit() { - parentUpdateFlag = false; + //parentUpdateFlag = false; } public ParentIndex getParentIndex() {
--- a/Main/jungle-main/util/IterableConverter.cs Fri Dec 16 00:25:03 2016 +0900 +++ b/Main/jungle-main/util/IterableConverter.cs Wed Jan 18 19:53:29 2017 +0900 @@ -30,14 +30,14 @@ return new IteratorConverter<A,B>(iterable.GetEnumerator(),converter); } - private class IteratorConverter<A,B> : IEnumerator<A> + private class IteratorConverter<C,D> : IEnumerator<C> { - public List<A> appLines { get; set; } + public List<C> appLines { get; set; } - private IEnumerator<B> iterator; - private Converter<A,B> converter; + private IEnumerator<D> iterator; + private Converter<C,D> converter; - public IteratorConverter(IEnumerator<B> _iterator,Converter<A,B> _converter) + public IteratorConverter(IEnumerator<D> _iterator,Converter<C,D> _converter) { iterator = _iterator; converter = _converter; @@ -48,7 +48,7 @@ return iterator.MoveNext(); } - public A Current + public C Current { get{ return converter.conv (iterator.Current); @@ -67,13 +67,13 @@ } public void Dispose() { - ((IEnumerator<A>)this.appLines).Dispose (); + ((IEnumerator<C>)this.appLines).Dispose (); } } - public interface Converter<A,B>{ - A conv (B _b); + public interface Converter<C,D>{ + C conv (D _b); } } \ No newline at end of file
--- a/Test/junge-main/data/list/ListTest.cs Fri Dec 16 00:25:03 2016 +0900 +++ b/Test/junge-main/data/list/ListTest.cs Wed Jan 18 19:53:29 2017 +0900 @@ -1,5 +1,6 @@ using UnityEngine; using System.Collections; +using JungleDB; public class ListTest : MonoBehaviour {
--- a/Test/junge-main/data/list/deleteTest.cs Fri Dec 16 00:25:03 2016 +0900 +++ b/Test/junge-main/data/list/deleteTest.cs Wed Jan 18 19:53:29 2017 +0900 @@ -1,6 +1,6 @@ using UnityEngine; using System.Collections; - +using JungleDB; public class deleteTest : MonoBehaviour { void Start () {
--- a/Test/junge-main/data/list/listAdd.cs Fri Dec 16 00:25:03 2016 +0900 +++ b/Test/junge-main/data/list/listAdd.cs Wed Jan 18 19:53:29 2017 +0900 @@ -1,6 +1,7 @@ using UnityEngine; using System.Collections; using System; +using JungleDB; public class listAdd : MonoBehaviour {
--- a/Test/junge-main/data/list/replaceTest.cs Fri Dec 16 00:25:03 2016 +0900 +++ b/Test/junge-main/data/list/replaceTest.cs Wed Jan 18 19:53:29 2017 +0900 @@ -1,4 +1,5 @@ using UnityEngine; +using JungleDB; public class replaceTest : MonoBehaviour {
--- a/Test/jungle-network/operations/NetworkTreeOperationLogTest.cs Fri Dec 16 00:25:03 2016 +0900 +++ b/Test/jungle-network/operations/NetworkTreeOperationLogTest.cs Wed Jan 18 19:53:29 2017 +0900 @@ -7,9 +7,9 @@ // Use this for initialization void Start () { // not work yet 10/23 13:33 - NetworkAppendChildAtOperation op = new NetworkAppendChildAtOperation(1); - NetworkNodePath path = new NetworkNodePath(); - NodePath npath = (NodePath)path.add(1); + // NetworkAppendChildAtOperation op = new NetworkAppendChildAtOperation(1); + // NetworkNodePath path = new NetworkNodePath(); + // NodePath npath = (NodePath)path.add(1); // NetworkTreeOperationLog log = new NetworkTreeOperationLog(); // log.add(npath, op);