Guid NextGuid() { TinkarId g = new TinkarId(guidNumber, ~guidNumber); guidNumber += 1; return(g.Uuid); }
public static VertexDTO ToVertex(this PBVertex value) { //# Tested TinkarId tid = new TinkarId(new Guid(value.VertexId.Id.ToByteArray())); return(new VertexDTO(tid.Uuid, value.VertexIndex, value.Meaning.ToConcept(), value.Properties.ToImmutableDictionary())); throw new NotImplementedException(); }
public PublicId(params Guid[] guids) { if (guids.Length < 1) { throw new Exception($"Can not create a private id with no parameters"); } else if (guids.Length == 1) { this.MultipleId = null; this.SingleId = new TinkarId(guids[0]); } else { List <TinkarId> guidUnionList = new List <TinkarId>(); // Insert into ordered position. Discard duplicates. void InsertOrdered(TinkarId newItem) { if (guidUnionList.Count == 0) { guidUnionList.Add(newItem); } Int32 i = guidUnionList.Count; while (i > 0) { Int32 cmpVal = newItem.CompareTo(guidUnionList[i - 1]); // discard duplicates. if (cmpVal == 0) { return; } if (cmpVal > 0) { break; } i -= 1; } guidUnionList.Insert(i, newItem); } for (Int32 i = 0; i < guids.Length; i++) { InsertOrdered(new TinkarId(guids[i])); } this.SingleId = new TinkarId(Guid.Empty); this.MultipleId = guidUnionList.ToArray(); } }
public void Verify() { Guid guid = Guid.NewGuid(); TinkarId guidUnion = new TinkarId(guid); Assert.True(sizeof(TinkarId) == sizeof(Guid)); Assert.True(guidUnion.Uuid == guid); byte[] gb = guid.ToByteArray(); Int64 la = BitConverter.ToInt64(gb, 0); Int64 lb = BitConverter.ToInt64(gb, 8); Assert.True(guidUnion.MostSignificantBits == la); Assert.True(guidUnion.LeastSignificantBits == lb); }
public void Insert() { TinkarId alpha = new TinkarId(1L, 0L); TinkarId beta = new TinkarId(2L, 0L); TinkarId delta = new TinkarId(3L, 0L); { PublicId pid = new PublicId(alpha.Uuid); Guid[] guids = pid.AsUuidArray; Assert.True(guids.Length == 1); Assert.True(guids[0].CompareTo(alpha.Uuid) == 0); } { PublicId pid = new PublicId(alpha.Uuid, beta.Uuid, delta.Uuid); Guid[] guids = pid.AsUuidArray; Assert.True(guids.Length == 3); Assert.True(guids[0].CompareTo(alpha.Uuid) == 0); Assert.True(guids[1].CompareTo(beta.Uuid) == 0); Assert.True(guids[2].CompareTo(delta.Uuid) == 0); } { PublicId pid = new PublicId(beta.Uuid, delta.Uuid, alpha.Uuid); Guid[] guids = pid.AsUuidArray; Assert.True(guids.Length == 3); Assert.True(guids[0].CompareTo(alpha.Uuid) == 0); Assert.True(guids[1].CompareTo(beta.Uuid) == 0); Assert.True(guids[2].CompareTo(delta.Uuid) == 0); } { PublicId pid = new PublicId(alpha.Uuid, delta.Uuid, beta.Uuid); Guid[] guids = pid.AsUuidArray; Assert.True(guids.Length == 3); Assert.True(guids[0].CompareTo(alpha.Uuid) == 0); Assert.True(guids[1].CompareTo(beta.Uuid) == 0); Assert.True(guids[2].CompareTo(delta.Uuid) == 0); } { PublicId pid = new PublicId(alpha.Uuid, beta.Uuid, alpha.Uuid, delta.Uuid, alpha.Uuid, alpha.Uuid); Guid[] guids = pid.AsUuidArray; Assert.True(guids.Length == 3); Assert.True(guids[0].CompareTo(alpha.Uuid) == 0); Assert.True(guids[1].CompareTo(beta.Uuid) == 0); Assert.True(guids[2].CompareTo(delta.Uuid) == 0); } }
public void BulkWrite() { const Int32 count = 1 * 1000000; PBConcept[] concepts = new PBConcept[count]; { using StopWatch s = new StopWatch("Creation"); for (Int32 i = 0; i < count; i++) { PBConcept concept = new PBConcept { PublicId = new PBPublicId() }; TinkarId tid = new TinkarId(Guid.NewGuid()); concept.PublicId.Id.Add(tid.ToPBTinkarId()); concepts[i] = concept; } } { using StopWatch s = new StopWatch("Writing"); using (var output = File.Create(@"c:\Temp\ProtobufTest.bin")) { for (Int32 i = 0; i < count; i++) { concepts[i].WriteTo(output); } } } { using StopWatch s = new StopWatch("Reading"); using (var input = File.OpenRead(@"c:\Temp\ProtobufTest.bin")) { var parser = PBConcept.Parser; for (Int32 i = 0; i < count; i++) { concepts[i] = parser.ParseFrom(input); } } } }