public virtual void TestSetFive_InOrder() { LeafBucket b = new LeafBucket(0); NUnit.Framework.Assert.AreSame(b, b.Set(Id(unchecked ((int)(0x11))), Id(unchecked ( (int)(0x81))), null)); NUnit.Framework.Assert.AreSame(b, b.Set(Id(unchecked ((int)(0x22))), Id(unchecked ( (int)(0x82))), null)); NUnit.Framework.Assert.AreSame(b, b.Set(Id(unchecked ((int)(0x33))), Id(unchecked ( (int)(0x83))), null)); NUnit.Framework.Assert.AreSame(b, b.Set(Id(unchecked ((int)(0x44))), Id(unchecked ( (int)(0x84))), null)); NUnit.Framework.Assert.AreSame(b, b.Set(Id(unchecked ((int)(0x55))), Id(unchecked ( (int)(0x85))), null)); NUnit.Framework.Assert.IsNull(b.GetNote(Id(unchecked ((int)(0x01))), null)); NUnit.Framework.Assert.AreEqual(Id(unchecked ((int)(0x81))), b.GetNote(Id(unchecked ( (int)(0x11))), null).GetData()); NUnit.Framework.Assert.AreEqual(Id(unchecked ((int)(0x82))), b.GetNote(Id(unchecked ( (int)(0x22))), null).GetData()); NUnit.Framework.Assert.AreEqual(Id(unchecked ((int)(0x83))), b.GetNote(Id(unchecked ( (int)(0x33))), null).GetData()); NUnit.Framework.Assert.AreEqual(Id(unchecked ((int)(0x84))), b.GetNote(Id(unchecked ( (int)(0x44))), null).GetData()); NUnit.Framework.Assert.AreEqual(Id(unchecked ((int)(0x85))), b.GetNote(Id(unchecked ( (int)(0x55))), null).GetData()); NUnit.Framework.Assert.IsNull(b.GetNote(Id(unchecked ((int)(0x66))), null)); }
/// <exception cref="System.IO.IOException"></exception> private ObjectId Write(NonNoteEntry list) { LeafBucket b = new LeafBucket(0); b.nonNotes = list; return(b.WriteTree(inserter)); }
public virtual void TestRemoveMissingNote() { LeafBucket b = new LeafBucket(0); NUnit.Framework.Assert.IsNull(b.GetNote(Id(unchecked ((int)(0x11))), null)); NUnit.Framework.Assert.AreSame(b, b.Set(Id(unchecked ((int)(0x11))), null, null)); NUnit.Framework.Assert.IsNull(b.GetNote(Id(unchecked ((int)(0x11))), null)); }
public virtual void TestEmpty() { LeafBucket b = new LeafBucket(0); NUnit.Framework.Assert.IsNull(b.GetNote(Id(unchecked ((int)(0x00))), null)); NUnit.Framework.Assert.IsNull(b.GetNote(Id(unchecked ((int)(0x01))), null)); NUnit.Framework.Assert.IsNull(b.GetNote(Id(unchecked ((int)(0xfe))), null)); }
/// <exception cref="NGit.Errors.MissingObjectException"></exception> /// <exception cref="System.IO.IOException"></exception> private InMemoryNoteBucket MergeLeafBucket(int treeDepth, LeafBucket bb, LeafBucket ob, LeafBucket tb) { bb = NotNullOrEmpty(bb); ob = NotNullOrEmpty(ob); tb = NotNullOrEmpty(tb); InMemoryNoteBucket result = new LeafBucket(treeDepth * 2); int bi = 0; int oi = 0; int ti = 0; while (bi < bb.Size() || oi < ob.Size() || ti < tb.Size()) { Note b = Get(bb, bi); Note o = Get(ob, oi); Note t = Get(tb, ti); Note min = Min(b, o, t); b = SameNoteOrNull(min, b); o = SameNoteOrNull(min, o); t = SameNoteOrNull(min, t); if (SameContent(o, t)) { result = AddIfNotNull(result, o); } else { if (SameContent(b, o)) { result = AddIfNotNull(result, t); } else { if (SameContent(b, t)) { result = AddIfNotNull(result, o); } else { result = AddIfNotNull(result, noteMerger.Merge(b, o, t, reader, inserter)); } } } if (b != null) { bi++; } if (o != null) { oi++; } if (t != null) { ti++; } } return(result); }
/// <summary>Attach (or remove) a note on an object.</summary> /// <remarks> /// Attach (or remove) a note on an object. /// If no note exists, a new note is stored. If a note already exists for the /// given object, it is replaced (or removed). /// This method only updates the map in memory. /// If the caller wants to attach a UTF-8 encoded string message to an /// object, /// <see cref="Set(NGit.AnyObjectId, string, NGit.ObjectInserter)">Set(NGit.AnyObjectId, string, NGit.ObjectInserter) /// </see> /// is a convenient /// way to encode and update a note in one step. /// </remarks> /// <param name="noteOn"> /// the object to attach the note to. This same ObjectId can later /// be used as an argument to /// <see cref="Get(NGit.AnyObjectId)">Get(NGit.AnyObjectId)</see> /// or /// <see cref="GetCachedBytes(NGit.AnyObjectId, int)">GetCachedBytes(NGit.AnyObjectId, int) /// </see> /// to read back the /// <code>noteData</code> /// . /// </param> /// <param name="noteData"> /// data to associate with the note. This must be the ObjectId of /// a blob that already exists in the repository. If null the note /// will be deleted, if present. /// </param> /// <exception cref="System.IO.IOException">a portion of the note space is not accessible. /// </exception> public virtual void Set(AnyObjectId noteOn, ObjectId noteData) { InMemoryNoteBucket newRoot = root.Set(noteOn, noteData, reader); if (newRoot == null) { newRoot = new LeafBucket(0); newRoot.nonNotes = root.nonNotes; } root = newRoot; }
public virtual void TestRemoveMakesEmpty() { LeafBucket b = new LeafBucket(0); NUnit.Framework.Assert.AreSame(b, b.Set(Id(unchecked ((int)(0x11))), Id(unchecked ( (int)(0x81))), null)); NUnit.Framework.Assert.AreEqual(Id(unchecked ((int)(0x81))), b.GetNote(Id(unchecked ( (int)(0x11))), null).GetData()); NUnit.Framework.Assert.IsNull(b.Set(Id(unchecked ((int)(0x11))), null, null)); NUnit.Framework.Assert.IsNull(b.GetNote(Id(unchecked ((int)(0x11))), null)); }
public virtual void TestSet_Replace() { LeafBucket b = new LeafBucket(0); NUnit.Framework.Assert.AreSame(b, b.Set(Id(unchecked ((int)(0x11))), Id(unchecked ( (int)(0x81))), null)); NUnit.Framework.Assert.AreEqual(Id(unchecked ((int)(0x81))), b.GetNote(Id(unchecked ( (int)(0x11))), null).GetData()); NUnit.Framework.Assert.AreSame(b, b.Set(Id(unchecked ((int)(0x11))), Id(unchecked ( (int)(0x01))), null)); NUnit.Framework.Assert.AreEqual(Id(unchecked ((int)(0x01))), b.GetNote(Id(unchecked ( (int)(0x11))), null).GetData()); }
/// <exception cref="System.IO.IOException"></exception> internal virtual InMemoryNoteBucket ContractIfTooSmall(AnyObjectId noteOn, ObjectReader or) { if (EstimateSize(noteOn, or) < LeafBucket.MAX_SIZE) { // We are small enough to just contract to a single leaf. InMemoryNoteBucket r = new LeafBucket(prefixLen); for (Sharpen.Iterator <Note> i = Iterator(noteOn, or); i.HasNext();) { r = r.Append(i.Next()); } r.nonNotes = nonNotes; return(r); } return(this); }
private LeafBucket ParseLeafTree() { LeafBucket leaf = new LeafBucket(prefixLen); MutableObjectId idBuf = new MutableObjectId(); for (; !Eof; Next(1)) { if (ParseObjectId(idBuf)) { leaf.ParseOneEntry(idBuf, EntryObjectId); } else { StoreNonNote(); } } return(leaf); }
internal override InMemoryNoteBucket Append(Note note) { int cell = Cell(note); InMemoryNoteBucket b = (InMemoryNoteBucket)table[cell]; if (b == null) { LeafBucket n = new LeafBucket(prefixLen + 2); table[cell] = n.Append(note); cnt++; } else { InMemoryNoteBucket n = b.Append(note); if (n != b) { table[cell] = n; } } return(this); }
/// <exception cref="System.IO.IOException"></exception> internal override InMemoryNoteBucket Set(AnyObjectId noteOn, AnyObjectId noteData , ObjectReader or) { int cell = Cell(noteOn); NoteBucket b = table[cell]; if (b == null) { if (noteData == null) { return(this); } LeafBucket n = new LeafBucket(prefixLen + 2); table[cell] = n.Set(noteOn, noteData, or); cnt++; return(this); } else { NoteBucket n = b.Set(noteOn, noteData, or); if (n == null) { table[cell] = null; cnt--; if (cnt == 0) { return(null); } return(ContractIfTooSmall(noteOn, or)); } else { if (n != b) { table[cell] = n; } } return(this); } }
public virtual void TestParseFive() { LeafBucket b = new LeafBucket(0); b.ParseOneEntry(Id(unchecked ((int)(0x11))), Id(unchecked ((int)(0x81)))); b.ParseOneEntry(Id(unchecked ((int)(0x22))), Id(unchecked ((int)(0x82)))); b.ParseOneEntry(Id(unchecked ((int)(0x33))), Id(unchecked ((int)(0x83)))); b.ParseOneEntry(Id(unchecked ((int)(0x44))), Id(unchecked ((int)(0x84)))); b.ParseOneEntry(Id(unchecked ((int)(0x55))), Id(unchecked ((int)(0x85)))); NUnit.Framework.Assert.IsNull(b.GetNote(Id(unchecked ((int)(0x01))), null)); NUnit.Framework.Assert.AreEqual(Id(unchecked ((int)(0x81))), b.GetNote(Id(unchecked ( (int)(0x11))), null).GetData()); NUnit.Framework.Assert.AreEqual(Id(unchecked ((int)(0x82))), b.GetNote(Id(unchecked ( (int)(0x22))), null).GetData()); NUnit.Framework.Assert.AreEqual(Id(unchecked ((int)(0x83))), b.GetNote(Id(unchecked ( (int)(0x33))), null).GetData()); NUnit.Framework.Assert.AreEqual(Id(unchecked ((int)(0x84))), b.GetNote(Id(unchecked ( (int)(0x44))), null).GetData()); NUnit.Framework.Assert.AreEqual(Id(unchecked ((int)(0x85))), b.GetNote(Id(unchecked ( (int)(0x55))), null).GetData()); NUnit.Framework.Assert.IsNull(b.GetNote(Id(unchecked ((int)(0x66))), null)); }
public _Iterator_121(LeafBucket _enclosing) { this._enclosing = _enclosing; }
private static Note Get(LeafBucket b, int i) { return(i < b.Size() ? b.Get(i) : null); }
private static LeafBucket NotNullOrEmpty(LeafBucket b) { return(b != null ? b : EMPTY_LEAF); }