private void WriteThis(Slot reservedSlot) { // We need a little dance here to keep filling free slots // with X bytes. The FreespaceManager would do it immediately // upon the free call, but then our CrashSimulatingTestCase // fails because we have the Xses in the file before flushing. Slot xByteSlot = null; int slotLength = SlotLength(); if (reservedSlot.Length() >= slotLength) { _slot = reservedSlot; reservedSlot = null; } else { _slot = AllocateSlot(true, slotLength); } ByteArrayBuffer buffer = new ByteArrayBuffer(_slot.Length()); buffer.WriteInt(_childId); _idGenerator.Write(buffer); TreeInt.Write(buffer, _ids); _container.WriteBytes(buffer, _slot.Address(), 0); _container.SystemData().IdSystemSlot(_slot); IRunnable commitHook = _container.CommitHook(); _container.SyncFiles(commitHook); FreeSlot(reservedSlot); }
public void Visit(object obj) { TreeInt idNode = (TreeInt)obj; candidates.Add(new Db4objects.Db4o.Internal.Query.Processor.QCandidate(candidates , null, idNode._key)); }
public void Visit(object a_object) { QCandidate candidate = (QCandidate)a_object; if (candidate.Include()) { TreeInt ids = new TreeInt(candidate._key); ByRef idsNew = new ByRef(); IEnumerator itPath = executionPath.GetEnumerator(); while (itPath.MoveNext()) { idsNew.value = null; string fieldName = (string)(itPath.Current); if (ids != null) { ids.Traverse(new _IVisitor4_385(this, stream, fieldName, idsNew)); } ids = (TreeInt)((TreeInt)idsNew.value); } if (ids != null) { ids.Traverse(new _IVisitor4_406(result)); } } }
protected virtual void AssertTreeInt(int[] expectedValues, TreeInt treeInt) { ExpectingVisitor visitor = ExpectingVisitor.CreateExpectingVisitor(expectedValues ); treeInt.Traverse(new _IVisitor4_113(visitor)); visitor.AssertExpectations(); }
private IList CreateList(int start) { IList expected = new ArrayList(); TreeInt expectedTree = CreateTree(start); Tree.Traverse(expectedTree, new _IVisitor4_79(expected)); return(expected); }
public virtual void TestCancelledTraversalWithStartingPointInTheTree() { IntByRef visits = new IntByRef(); TreeInt tree = CreateTree(); Tree.Traverse(tree, new TreeInt(6), new _ICancellableVisitor4_41(visits)); Assert.AreEqual(1, visits.value); }
public virtual void TestUnCancelledTraversalWithStartingPointNotInTheTree() { IList actual = new ArrayList(); TreeInt tree = CreateTree(); Tree.Traverse(tree, new TreeInt(5), new _ICancellableVisitor4_54(actual)); IteratorAssert.AreEqual(CreateList(6).GetEnumerator(), actual.GetEnumerator()); }
internal virtual void CreateIDMapping(DefragmentServicesImpl context, int objectID , bool isClassID) { if (BatchFull()) { Flush(context); } _ids = TreeInt.Add(_ids, (isClassID ? -objectID : objectID)); }
public void Visit(object obj) { TreeInt treeInt = (TreeInt)obj; if (treeInt._key == 1) { lockedTree.Add(new TreeInt(2)); } }
internal void FreePrefetchedIDs(IIdSystem idSystem) { if (_prefetchedIDs == null) { return; } idSystem.ReturnUnusedIds(_prefetchedIDs); _prefetchedIDs = null; }
private Tree CreateTree(int[] values) { Tree tree = new TreeInt(values[0]); for (int i = 1; i < values.Length; i++) { tree = tree.Add(new TreeInt(values[i])); } return(tree); }
public static TreeInt AddToTree(TreeInt tree, IIndexedNode node) { var i = node.GetEnumerator(); while (i.MoveNext()) { var composite = (IFieldIndexKey) i.Current; tree = (TreeInt) Tree.Add(tree, new TreeInt(composite.ParentID())); } return tree; }
private TreeInt CreateTree(int start) { TreeInt tree = null; for (int i = start; i < Count; i += 3) { tree = ((TreeInt)Tree.Add(tree, new TreeInt(i))); } return(tree); }
public void Visit(object obj) { int id = ((int)obj); TreeInt newNode = new TreeInt(id); duplicates.value = Tree.Add(((Tree)duplicates.value), newNode); if (newNode.Size() != 0) { this._enclosing.Add(id); } }
public bool Match(object current) { int id = ((int)current); if (this.ids.Find(id) != null) { return(false); } this.ids = (TreeInt)((TreeInt)this.ids.Add(new TreeInt(id))); return(true); }
public static TreeInt AddToTree(TreeInt tree, IIndexedNode node) { var i = node.GetEnumerator(); while (i.MoveNext()) { var composite = (IFieldIndexKey)i.Current; tree = (TreeInt)Tree.Add(tree, new TreeInt(composite.ParentID())); } return(tree); }
public IEnumerator ExecuteSnapshot(Collection4 executionPath) { IIntIterator4 indexIterator = new IntIterator4Adaptor(IterateIndex(ProcessFieldIndexes ())); Tree idRoot = TreeInt.AddAll(null, indexIterator); IEnumerator snapshotIterator = new TreeKeyIterator(idRoot); IEnumerator singleObjectQueryIterator = SingleObjectSodaProcessor(snapshotIterator ); return(MapIdsToExecutionPath(singleObjectQueryIterator, executionPath)); }
public bool Match(object current) { var id = ((int)current); if (ids.Find(id) != null) { return(false); } ids = (TreeInt)ids.Add(new TreeInt(id)); return(true); }
public virtual void AddKeyCheckDuplicates(int a_key) { if (_checkDuplicates) { TreeInt newNode = new TreeInt(a_key); _candidates = Tree.Add(_candidates, newNode); if (newNode._size == 0) { return; } } Add(a_key); }
public virtual void AddKeyCheckDuplicates(int a_key) { if (_checkDuplicates) { var newNode = new TreeInt(a_key); _candidates = Tree.Add(_candidates, newNode); if (newNode._size == 0) { return; } } Add(a_key); }
public override int MappedId(int oldID) { int classID = MappedClassID(oldID); if (classID != 0) { return(classID); } TreeIntObject res = (TreeIntObject)TreeInt.Find(_tree, oldID); if (res != null) { return((int)res._object); } return(0); }
public override void Write(LocalObjectContainer container) { Slot slot = container.AllocateSlot(MarshalledLength()); while (slot.Length() < MarshalledLength()) { // This can happen if DatabaseGrowthSize is configured. // Allocating a slot may produce an additional entry // in this FreespaceManager. container.Free(slot); slot = container.AllocateSlot(MarshalledLength()); } ByteArrayBuffer buffer = new ByteArrayBuffer(slot.Length()); TreeInt.Write(buffer, (TreeInt)_freeBySize); container.WriteEncrypt(buffer, slot.Address(), 0); container.SystemData().InMemoryFreespaceSlot(slot); }
public void Visit(int id) { TreeInt ids = new TreeInt(id); ByRef idsNew = new ByRef(); IEnumerator itPath = _executionPath.GetEnumerator(); while (itPath.MoveNext()) { idsNew.value = null; string fieldName = (string)(itPath.Current); ids.Traverse(new _IVisitor4_508(this, fieldName, idsNew)); ids = (TreeInt)((TreeInt)idsNew.value); if (ids == null) { return; } } ids.Traverse(new _IVisitor4_529(this)); }
public virtual void Flush(DefragmentServicesImpl context) { if (_ids == null) { return; } IEnumerator idIter = new TreeKeyIterator(_ids); while (idIter.MoveNext()) { int objectID = ((int)idIter.Current); bool isClassID = false; if (objectID < 0) { objectID = -objectID; isClassID = true; } // seen object ids don't come by here anymore - any other candidates? context.MapIDs(objectID, context.TargetNewId(), isClassID); } context.Mapping().Commit(); _ids = null; }
public virtual void PrefetchedIDConsumed(int id) { _prefetchedIDs = ((TreeInt) _prefetchedIDs.RemoveLike(new TreeInt(id))); }
public void Add(TreeInt node) { tree = (TreeInt)((TreeInt)Tree.Add(tree, node)); }
public IdTreeQueryResult(Transaction transaction, IIntIterator4 ids) : base(transaction ) { _ids = TreeInt.AddAll(null, ids); }
public void Visit(object obj) { var id = ((int) obj); var newNode = new TreeInt(id); duplicates.value = Tree.Add(((Tree) duplicates.value), newNode); if (newNode.Size() != 0) { _enclosing.Add(id); } }
public virtual void AddPrefetchedID(int id) { _prefetchedIDs = ((TreeInt)Tree.Add(_prefetchedIDs, new TreeInt(id))); }
public void Visit(object a_object) { var candidate = (QCandidate) a_object; if (candidate.Include()) { var ids = new TreeInt(candidate._key); var idsNew = new ByRef(); var itPath = executionPath.GetEnumerator(); while (itPath.MoveNext()) { idsNew.value = null; var fieldName = (string) (itPath.Current); if (ids != null) { ids.Traverse(new _IVisitor4_385(this, stream, fieldName, idsNew)); } ids = (TreeInt) idsNew.value; } if (ids != null) { ids.Traverse(new _IVisitor4_406(result)); } } }
public _IPredicate4_573() { ids = new TreeInt(0); }
public bool Match(object current) { var id = ((int) current); if (ids.Find(id) != null) { return false; } ids = (TreeInt) ids.Add(new TreeInt(id)); return true; }
public void Visit(object node) { idsNew.value = TreeInt.Add(((TreeInt)idsNew.value), ((TreeInt)node)._key); }
public void Add(TreeInt node) { tree = (TreeInt) Tree.Add(tree, node); }
public virtual void AddPrefetchedID(int id) { _prefetchedIDs = ((TreeInt) Tree.Add(_prefetchedIDs, new TreeInt(id))); }
private void AssertComplexItems(int[] expectedFoos, TreeInt found) { Assert.IsNotNull(found); AssertTreeInt(MapToObjectIds(CreateComplexItemQuery(), expectedFoos), found); }
public virtual void AddId(int id) { _ids = (TreeInt) Tree.Add(_ids, new TreeInt(id)); }
public virtual void PrefetchedIDConsumed(int id) { _prefetchedIDs = ((TreeInt)_prefetchedIDs.RemoveLike(new TreeInt(id))); }
public static void Main(string[] args) { ConsoleKeyInfo key; do { Console.Clear(); Console.WriteLine("1 - Finding the root."); Console.WriteLine("2 - Round dance."); Console.WriteLine("3 - Ride the horse."); Console.WriteLine("4 - Longest path."); Console.WriteLine("5 - Sorting."); Console.WriteLine("q - Quit"); key = Console.ReadKey (); Console.WriteLine(); switch( key.KeyChar) { case '1': Console.WriteLine ("Finding the root."); Console.WriteLine ("Enter number of nodes:"); try { int cNodes = int.Parse (Console.ReadLine ()); Console.WriteLine ("Enter number of edges:"); int cEdges = int.Parse(Console.ReadLine ()); Graph<int, Node<int>> plainGraph = new LimitedGraph<int, Node<int>> (cNodes); Console.WriteLine ("Enter nodes:"); for (var i=0; i<cEdges; i++) { int[] pair = Console.ReadLine ().Split ().Select (h => int.Parse (h)).ToArray (); try { plainGraph.AddPair(pair[1], pair[0]); } catch (OverflowException e) { Console.WriteLine (e.Message); i--; } } plainGraph.PrintRoot(); } catch (FormatException e) { Console.WriteLine (e.Message); } break; case '2': Console.WriteLine("Round dance."); Console.WriteLine("Enter number of friendships:"); try { int fCount = int.Parse(Console.ReadLine()); Console.WriteLine("Enter leader number:"); int leader = int.Parse(Console.ReadLine()); Console.WriteLine("Enter friendships:"); RoundGraph<int, Node<int>> roundDance = new RoundGraph<int, Node<int>> (leader); for( var i=0; i<fCount; i++) { int[] pair = Console.ReadLine ().Split ().Select (h => int.Parse (h)).ToArray (); roundDance.AddPair(pair[0], pair[1]); roundDance.AddPair(pair[1], pair[0]); } Console.WriteLine("The longest round dance has {0} people", roundDance.GetLongestDance()); } catch (FormatException e) { Console.WriteLine (e.Message); } catch (IndexOutOfRangeException e) { Console.WriteLine (e.Message); } break; case '3': Console.WriteLine("Ride the horse"); try { Console.WriteLine("Rows:"); int rows = int.Parse(Console.ReadLine()); Console.WriteLine("Cols:"); int cols = int.Parse(Console.ReadLine()); Console.WriteLine("Start row:"); int startRow = int.Parse(Console.ReadLine()); Console.WriteLine("Start col:"); int startCol = int.Parse(Console.ReadLine()); var horse = new Horse(rows, cols); var start = new Horse.Position(startRow, startCol, 1); horse.TraverseBoard(start); Console.WriteLine("Column {0}:", cols/2); for(var row=0; row<rows; row++) { Console.WriteLine(horse.Board[row,cols/2]); } } catch( FormatException e) { Console.WriteLine(e.Message); } break; case '4': Console.WriteLine("Longest path."); Console.WriteLine ("Enter number of nodes:"); try { int cNodes = int.Parse (Console.ReadLine ()); Console.WriteLine ("Enter number of edges:"); int cEdges = int.Parse(Console.ReadLine ()); TreeInt<Node<int>> tree = new TreeInt<Node<int>> (cNodes); Console.WriteLine ("Enter nodes:"); for (var i=0; i<cEdges; i++) { int[] pair = Console.ReadLine ().Split ().Select (h => int.Parse (h)).ToArray (); try { tree.AddPair(pair[1], pair[0]); } catch (IndexOutOfRangeException e) { Console.WriteLine (e.Message); i--; } catch (OverflowException e) { Console.WriteLine (e.Message); i--; } catch(InvalidOperationException e) { Console.WriteLine(e.Message); i--; } } Console.WriteLine("The greatest sum from leaf to leaf: {0}", tree.CalcLongestLeafPath()); } catch (FormatException e) { Console.WriteLine (e.Message); } break; case '5': try{ Console.WriteLine("Sorting."); Console.WriteLine("Enter numbers count:"); int numCount = int.Parse(Console.ReadLine()); Console.WriteLine("Enter {0} numbers:", numCount); int[] numbers = Console.ReadLine ().Split ().Select (h => int.Parse (h)).ToArray (); Console.WriteLine("Enter number of consecutive elements to reorder:"); int reorderCount = int.Parse(Console.ReadLine()); var sortOp = new SortOperations(numbers,reorderCount); Console.WriteLine("{0}", sortOp.GetSortOperations()); } catch(FormatException e) { Console.WriteLine(e.Message); } break; } Console.ReadKey(); }// do while( 'q' != key.KeyChar ); }
public virtual Tree ToQCandidate(QCandidates candidates) { return(TreeInt.ToQCandidate(ToTreeInt(), candidates)); }
public virtual void AddId(int id) { _ids = (TreeInt)Tree.Add(_ids, new TreeInt(id)); }