public CheckByteArray(PilePointer pp, int il, byte fb, byte lb) { Ptr = pp; IdxLast = il; FirstByte = fb; LastByte = lb; }
private PilePointer findPP(string Key) { char[] keys = Key.ToCharArray(); string strKey = ""; PilePointer currentPP = m_Root; PrefixTreeNode current = (PrefixTreeNode)m_Pile.Get(currentPP); bool contains = false; foreach (char charKey in keys) { strKey += charKey; int i = 0; contains = false; for (i = 0; i < current.Children.Length; i++) { if (current.Children[i].Key > charKey) { break; } if (current.Children[i].Key == charKey) { contains = true; break; } } if (i >= current.Children.Length) { break; } currentPP = current.Children[i].ValuePP; current = (PrefixTreeNode)m_Pile.Get(currentPP); } return(contains ? currentPP : default(PilePointer)); }
private IEnumerable <KeyValuePair <string, T> > getNextValuePairs(PilePointer pp, string strKey) { if (pp == default(PilePointer)) { yield break; } var current = (PrefixTreeNode)m_Pile.Get(pp); if (current.ValuePP != default(PilePointer)) { yield return(new KeyValuePair <string, T>(strKey, (T)m_Pile.Get(current.ValuePP))); } foreach (Entry entry in current.Children) { if (entry.ValuePP != default(PilePointer)) { foreach (var nextValuePair in getNextValuePairs(entry.ValuePP, strKey + entry.Key)) { yield return(nextValuePair); } } else { yield break; } } }
internal LinkedListNode(IPile pile, PilePointer self, LinkedList <T> list) { m_Pile = pile; Node = m_Pile.Get(self) as NodeData; if (Node == null) { throw new AccessViolationException(); } List = list; }
private void putValue(PilePointer currentPP, string key, T value, string strKey, int i) { if (i > key.Length) { throw new IndexOutOfRangeException(); } if (currentPP == default(PilePointer)) { throw new IndexOutOfRangeException(); } var current = (PrefixTreeNode)m_Pile.Get(currentPP); if (key == strKey) { if (current.ValuePP != default(PilePointer)) { m_Pile.Put(current.ValuePP, value); } else { current.ValuePP = m_Pile.Put(value); m_Pile.Put(currentPP, current); m_Count++; } return; } for (int j = 0; j < current.Children.Length; j++) { if (current.Children[j].ValuePP == default(PilePointer)) { var tmp = newPrefixTreeNode(); Entry entry = new Entry() { Key = key[i], ValuePP = m_Pile.Put(tmp) }; insertEntry(j, ref current.Children, entry); m_Pile.Put(currentPP, current); } else if (current.Children[j].Key > key[i]) { var tmp = newPrefixTreeNode(); Entry entry = new Entry() { Key = key[i], ValuePP = m_Pile.Put(tmp) }; insertEntry(j, ref current.Children, entry); m_Pile.Put(currentPP, current); } if (current.Children[j].Key == key[i]) { putValue(current.Children[j].ValuePP, key, value, strKey + current.Children[j].Key, i + 1); break; } } }
private T find(string key) { T result = default(T); PilePointer currentPP = findPP(key); if (currentPP != default(PilePointer)) { PrefixTreeNode current = (PrefixTreeNode)m_Pile.Get(currentPP); result = current.ValuePP != default(PilePointer) ? (T)m_Pile.Get(current.ValuePP) : default(T); } return(result); }
private void setValue(string key, T value) { char[] keys = key.ToCharArray(); string strKey = ""; PilePointer currentPP = m_Root; PrefixTreeNode current = (PrefixTreeNode)m_Pile.Get(currentPP); foreach (char charKey in keys) { strKey += charKey; int i = 0; for (i = 0; i < current.Children.Length; i++) { if (current.Children[i].ValuePP == default(PilePointer)) { var tmp = newPrefixTreeNode(); Entry entry = new Entry() { Key = charKey, ValuePP = m_Pile.Put(tmp) }; insertEntry(i, ref current.Children, entry); m_Pile.Put(currentPP, current); } else if (current.Children[i].Key > charKey) { var tmp = newPrefixTreeNode(); Entry entry = new Entry() { Key = charKey, ValuePP = m_Pile.Put(tmp) }; insertEntry(i, ref current.Children, entry); m_Pile.Put(currentPP, current); } if (current.Children[i].Key == charKey) { break; } } currentPP = current.Children[i].ValuePP; current = (PrefixTreeNode)m_Pile.Get(currentPP); } if (current.ValuePP != default(PilePointer)) { m_Pile.Put(current.ValuePP, value); } else { current.ValuePP = m_Pile.Put(value); m_Pile.Put(currentPP, current); m_Count++; } }
public bool Remove(string key) { bool result = false; PilePointer currentPP = findPP(key); if (currentPP != default(PilePointer)) { PrefixTreeNode current = (PrefixTreeNode)m_Pile.Get(currentPP); m_Pile.Delete(current.ValuePP); current.ValuePP = default(PilePointer); m_Pile.Put(currentPP, current); m_Count--; } return(result); }
public void StringCorrectess(int len, int deleteEvery, int parallel) { using (var pile = new DefaultPile()) { pile.Start(); var bag = new ConcurrentBag <PilePointer>(); var deleted = 0; Parallel.For(0, len, new ParallelOptions { MaxDegreeOfParallelism = parallel }, (i) => { var str = new string('a', i); PilePointer pp = PilePointer.Invalid; if (i % 2 == 0) { if (bag.TryTake(out pp)) { pile.Put(pp, str); } } pp = pile.Put(str, preallocateBlockSize: i + 100); var got = pile.Get(pp) as string; Aver.AreEqual(str, got); if (i % deleteEvery == 0) { PilePointer dp; if (bag.TryTake(out dp)) { if (pile.Delete(dp, false)) { Interlocked.Increment(ref deleted); } } bag.Add(pp); } }); Console.WriteLine("Deleted {0:n0}", deleted); } }
private void clearItem(PilePointer pp) { if (pp == default(PilePointer)) { return; } PrefixTreeNode current = (PrefixTreeNode)m_Pile.Get(pp); foreach (Entry entry in current.Children) { if (entry.ValuePP != default(PilePointer)) { clearItem(entry.ValuePP); } } if (current.ValuePP != default(PilePointer)) { m_Pile.Delete(current.ValuePP); } m_Pile.Delete(pp); }
private void getNextKey(ref string[] result, PilePointer pp, ref int i, string strKey) { if (pp == default(PilePointer)) { return; } var current = (PrefixTreeNode)m_Pile.Get(pp); if (current.ValuePP != default(PilePointer)) { result[i++] = strKey; } foreach (Entry entry in current.Children) { if (entry.ValuePP != default(PilePointer)) { getNextKey(ref result, entry.ValuePP, ref i, strKey + entry.Key); } else { break; } } }
/// <summary> /// Deletes object from pile by its pointer returning true if there is no access violation /// and pointer is pointing to the valid object, throws otherwise unless /// throwInvalid is set to false /// </summary> public bool Delete(PilePointer ptr, bool throwInvalid = true) { if (!Running) return false; var segs = m_Segments; if (ptr.Segment<0 || ptr.Segment>=segs.Count) { if (throwInvalid) throw new PileAccessViolationException(StringConsts.PILE_AV_BAD_SEGMENT_ERROR + ptr.ToString()); return false; } var seg = segs[ptr.Segment]; if (seg==null || seg.DELETED!=0) { if (throwInvalid) throw new PileAccessViolationException(StringConsts.PILE_AV_BAD_SEGMENT_ERROR + ptr.ToString()); return false; } Interlocked.Increment(ref m_stat_DeleteCount); var removeEmptySegment = false; if (!getWriteLock(seg)) return false;//Service shutting down try { //2nd check under lock if (seg.DELETED!=0) throw new PileAccessViolationException(StringConsts.PILE_AV_BAD_SEGMENT_ERROR + ptr.ToString()); var data = seg.Data; var addr = ptr.Address; if (addr<0 || addr>=data.LongLength-CHUNK_HDER_SZ) { if (throwInvalid) throw new PileAccessViolationException(StringConsts.PILE_AV_BAD_ADDR_EOF_ERROR + ptr.ToString()); return false; } var cflag = readChunkFlag(data, addr); addr+=3; if (cflag!=chunkFlag.Used) { if (throwInvalid) throw new PileAccessViolationException(StringConsts.PILE_AV_BAD_ADDR_CHUNK_FLAG_ERROR + ptr.ToString()); return false; } seg.Deallocate(ptr.Address); //release segment //if nothing left allocated and either reuseSpace or 50/50 chance if (seg.ObjectCount==0 && (m_AllocMode==AllocationMode.ReuseSpace || (ptr.Address & 1) == 1)) { Thread.VolatileWrite(ref seg.DELETED, 1);//Mark as deleted removeEmptySegment = true; } } finally { releaseWriteLock(seg); } if (removeEmptySegment) //it is ok that THIS is not under segment write lock BECAUSE lock(m_SegmentsLock) // the segment was marked as DELETED, and it can not be re-allocated as it was marked under the lock { var newSegs = new List<_segment>(m_Segments); if (newSegs.Count>0)//safeguard, always true { if (newSegs.Count==1) { if (newSegs[0]==seg) newSegs.Clear(); } else if (seg==newSegs[newSegs.Count-1]) newSegs.Remove( seg ); else { for(var k=0; k<newSegs.Count; k++) if (newSegs[k] == seg) { newSegs[k] = null; break; } } } m_Segments = newSegs;//atomic }//lock barrier return true; }
/// <summary> /// Returns a CLR object by its pointer or throws access violation if pointer is invalid /// </summary> public object Get(PilePointer ptr) { if (!Running) return null; var segs = m_Segments; if (ptr.Segment<0 || ptr.Segment>=segs.Count) throw new PileAccessViolationException(StringConsts.PILE_AV_BAD_SEGMENT_ERROR + ptr.ToString()); var seg = segs[ptr.Segment]; if (seg==null || seg.DELETED!=0) throw new PileAccessViolationException(StringConsts.PILE_AV_BAD_SEGMENT_ERROR + ptr.ToString()); Interlocked.Increment(ref m_stat_GetCount); if (!getReadLock(seg)) return null;//Service shutting down try { //2nd check under lock if (seg.DELETED!=0) throw new PileAccessViolationException(StringConsts.PILE_AV_BAD_SEGMENT_ERROR + ptr.ToString()); var data = seg.Data; var addr = ptr.Address; if (addr<0 || addr>=data.LongLength-CHUNK_HDER_SZ) throw new PileAccessViolationException(StringConsts.PILE_AV_BAD_ADDR_EOF_ERROR + ptr.ToString()); var cflag = readChunkFlag(data, addr); addr+=3; if (cflag!=chunkFlag.Used) throw new PileAccessViolationException(StringConsts.PILE_AV_BAD_ADDR_CHUNK_FLAG_ERROR + ptr.ToString()); var payloadSize = data.ReadBEInt32(ref addr); if (payloadSize>data.Length) throw new PileAccessViolationException(StringConsts.PILE_AV_BAD_ADDR_PAYLOAD_SIZE_ERROR.Args(ptr, payloadSize)); //not used now //var serVer = data[addr]; addr++; return deserialize(data, addr, payloadSize); } finally { releaseReadLock(seg); } }
/// <summary> /// Puts a CLR object into the pile and returns a newly-allocated pointer. /// Throws out-of-space if there is not enough space in the pile and limits are set. /// Optional lifeSpanSec is ignored by this implementation /// </summary> public PilePointer Put(object obj, uint lifeSpanSec = 0) { if (!Running) return PilePointer.Invalid; if (obj==null) throw new PileException(StringConsts.ARGUMENT_ERROR+GetType().Name+".Put(obj==null)"); Interlocked.Increment(ref m_stat_PutCount); //1 serialize to determine the size int serializedSize; byte serializerVersion; var buffer = serialize(obj, out serializedSize, out serializerVersion); var payloadSize = IntMath.Align8(serializedSize); var chunkSize = CHUNK_HDER_SZ + payloadSize; if (chunkSize>m_SegmentSize) throw new PileOutOfSpaceException(StringConsts.PILE_OBJECT_LARGER_SEGMENT_ERROR.Args(payloadSize)); while(true) { if (!Running) return PilePointer.Invalid; var segs = m_Segments; for(var idxSegment=0; idxSegment<segs.Count; idxSegment++) { var seg = segs[idxSegment]; if (seg==null) continue; if (seg.DELETED!=0) continue; var sused = seg.UsedBytes; if (seg.FreeCapacity > chunkSize) { if (!getWriteLock(seg)) return PilePointer.Invalid; try { if (Thread.VolatileRead(ref seg.DELETED)==0 && seg.FreeCapacity > chunkSize) { var adr = seg.Allocate(buffer, payloadSize, serializerVersion); if (adr>=0) return new PilePointer(idxSegment, adr);//allocated before crawl var utcNow = DateTime.UtcNow; if ((utcNow - seg.LastCrawl).TotalSeconds > (m_AllocMode==AllocationMode.FavorSpeed ? 30 : 5)) { //could not fit, try to reclaim seg.Crawl(); seg.LastCrawl = utcNow; //try again adr = seg.Allocate(buffer, payloadSize, serializerVersion); if (adr>=0) return new PilePointer(idxSegment, adr);//allocated after crawl } //if we are here - still could not allocate, will try next segment in iteration } } finally { releaseWriteLock(seg); } } }//for //if we are here, we still could not allocate space of existing segments if (m_AllocMode==AllocationMode.FavorSpeed) break; var nsegs = m_Segments; if (segs.Count >= nsegs.Count) break;//if segment list grew already, repeat the whole thing again as more space may have become available }//while //allocate segment lock(m_SegmentsLock) { if ( (m_MaxMemoryLimit>0 && AllocatedMemoryBytes+m_SegmentSize > m_MaxMemoryLimit )|| (m_MaxSegmentLimit>0 && (m_Segments.Count( s => s!=null ) + 1) > m_MaxSegmentLimit ) ) throw new PileOutOfSpaceException(StringConsts.PILE_OUT_OF_SPACE_ERROR.Args(m_MaxMemoryLimit, m_MaxSegmentLimit, m_SegmentSize)); var newSeg = new _segment(this); var newSegs = new List<_segment>(m_Segments); newSegs.Add( newSeg ); var adr = newSeg.Allocate(buffer, payloadSize, serializerVersion); var pp = new PilePointer(newSegs.Count-1, adr); m_Segments = newSegs; return pp; } }
public int SizeOf(PilePointer ptr) { if (!Running) return 0; var segs = m_Segments; if (ptr.Segment<0 || ptr.Segment>=segs.Count) throw new PileAccessViolationException(StringConsts.PILE_AV_BAD_SEGMENT_ERROR + ptr.ToString()); var seg = segs[ptr.Segment]; if (seg==null || seg.DELETED!=0) throw new PileAccessViolationException(StringConsts.PILE_AV_BAD_SEGMENT_ERROR + ptr.ToString()); if (!getReadLock(seg)) return 0;//Service shutting down try { //2nd check under lock if (seg.DELETED!=0) throw new PileAccessViolationException(StringConsts.PILE_AV_BAD_SEGMENT_ERROR + ptr.ToString()); var data = seg.Data; var addr = ptr.Address; if (addr<0 || addr>=data.LongLength-CHUNK_HDER_SZ) throw new PileAccessViolationException(StringConsts.PILE_AV_BAD_ADDR_EOF_ERROR + ptr.ToString()); var cflag = readChunkFlag(data, addr); addr+=3; if (cflag!=chunkFlag.Used) throw new PileAccessViolationException(StringConsts.PILE_AV_BAD_ADDR_CHUNK_FLAG_ERROR + ptr.ToString()); var payloadSize = data.ReadBEInt32(ref addr); return payloadSize; } finally { releaseReadLock(seg); } }
public bool Rejuvenate(PilePointer ptr) { return false; }
public CheckTRow(PilePointer ptr, GDID id, string address) { Ptr = ptr; Id = id; Address = address; }
public PileEntry(PilePointer ptr, DataType tp, int size) { Pointer = ptr; Type = tp; Size = size; }
public AllTypesDoc Populate(bool withDoc = true) { Enum = CustomEnumType.DElement; EnumN = CustomEnumType.C; EnumArray = new CustomEnumType[] { CustomEnumType.A, CustomEnumType.B }; EnumList = new List <CustomEnumType> { CustomEnumType.C, CustomEnumType.DElement }; EnumNArray = new CustomEnumType?[] { null, null, CustomEnumType.B }; EnumNList = new List <CustomEnumType?> { CustomEnumType.C, null, null, CustomEnumType.DElement }; if (withDoc) { Doc = new AllTypesDoc().Populate(false); DocArray = new AllTypesDoc[] { null, null, new AllTypesDoc().Populate(false) }; DocList = new List <AllTypesDoc> { new AllTypesDoc().Populate(false) }; } Gdid = new GDID(12, 23423); GdidN = new GDID(24, 243534); GdidArray = new GDID[] { new GDID(122, 2342543), new GDID(122, 233423), new GDID(12, 232423) }; GdidList = new List <GDID> { new GDID(122, 2342543), new GDID(122, 233423), new GDID(12, 232423) }; GdidNArray = new GDID?[] { new GDID(122, 2342543), null, new GDID(12, 232423) }; GdidNList = new List <GDID?> { null, new GDID(122, 233423), new GDID(12, 232423) }; GdidSymbol = new GDIDSymbol(new GDID(12, 23423), "fsdfsd"); GdidSymbolN = new GDIDSymbol(new GDID(312, 323423), "jezl kulaz"); GdidSymbolArray = new GDIDSymbol[] { new GDIDSymbol(new GDID(1, 53), "fs44dfsd"), new GDIDSymbol(new GDID(2, 923), "liopa") }; GdidSymbolList = new List <GDIDSymbol> { new GDIDSymbol(new GDID(1, 53), "fs44dfsd"), new GDIDSymbol(new GDID(2, 923), "liopa") }; GdidSymbolNArray = new GDIDSymbol?[] { null, new GDIDSymbol(new GDID(2, 923), "liopa") }; GdidSymbolNList = new List <GDIDSymbol?> { new GDIDSymbol(new GDID(1, 53), "fs44dfsd"), null }; Guid = System.Guid.NewGuid(); GuidN = System.Guid.NewGuid(); GuidArray = new Guid[] { System.Guid.NewGuid(), System.Guid.NewGuid() }; GuidList = new List <Guid> { System.Guid.NewGuid(), System.Guid.NewGuid(), System.Guid.NewGuid() }; GuidNArray = new Guid?[] { null, System.Guid.NewGuid() }; GuidNList = new List <Guid?> { System.Guid.NewGuid(), null }; Atom = Atom.Encode("a"); AtomN = Atom.Encode("ae3"); AtomArray = new Atom[] { Atom.Encode("a2e3"), Atom.Encode("a1e3") }; AtomList = new List <Atom> { Atom.Encode("a3"), Atom.Encode("23"), Atom.Encode("r4") }; AtomNArray = new Atom?[] { null, Atom.Encode("a3") }; AtomNList = new List <Atom?> { Atom.Encode("2a3"), null }; Fid = new FID(23); FidN = new FID(323); FidArray = new FID[] { new FID(23), new FID(123) }; FidList = new List <FID> { new FID(233), new FID(23), new FID(23) }; FidNArray = new FID?[] { null, new FID(223) }; FidNList = new List <FID?> { new FID(423), null }; Pileptr = new PilePointer(1, 23); PileptrN = new PilePointer(1, 23); PileptrArray = new PilePointer[] { new PilePointer(1, 243), new PilePointer(1, 223) }; PileptrList = new List <PilePointer> { new PilePointer(21, 23), new PilePointer(1, 23), new PilePointer(1, 263) }; PileptrNArray = new PilePointer?[] { null, new PilePointer(1, 293) }; PileptrNList = new List <PilePointer?> { new PilePointer(1, 223), null }; NLSMap = new NLSMap("{eng: {n: 'Cucumber',d: 'It is green'}, deu: {n: 'Gurke',d: 'Es ist grün'}}"); NLSMapN = new NLSMap("{eng: {n: 'Cur',d: 'Is'}}"); NLSMapArray = new NLSMap[] { new NLSMap("{eng: {n: 'Cewqeur',d: 'Is'}}"), new NLSMap("{eng: {n: 'Cur23',d: 'Isee'}}") }; NLSMapList = new List <NLSMap> { new NLSMap("{eng: {n: 'Cr',d: 'Is'}}"), new NLSMap("{eng: {n: 'Currr',d: 'Iws'}}"), new NLSMap("{eng: {n: 'ertCur',d: 'rtIs'}}") }; NLSMapNArray = new NLSMap?[] { null, new NLSMap("{eng: {n: 'Cweur',d: 'Is'}}") }; NLSMapNList = new List <NLSMap?> { new NLSMap("{eng: {n: 'Cuer',d: 'Is'}}"), null }; Amount = new Amount("usd", 123.11m); AmountN = new Amount("usd", 223.11m); AmountArray = new Amount[] { new Amount("usd", 123.11m), new Amount("usd", 223.11m) }; AmountList = new List <Amount> { new Amount("usd", 123.11m), new Amount("usd", 253.11m), new Amount("usd", 243.11m) }; AmountNArray = new Amount?[] { null, new Amount("usd", 323.11m) }; AmountNList = new List <Amount?> { new Amount("usd", 523.11m), null }; StringMap = new StringMap { { "a", "aaa" }, { "b", "bbb" } }; StringMapArray = new StringMap[] { new StringMap { { "a", "aaa" }, { "b", "bbb" } }, null, new StringMap { { "23a", "23423weaaa" } } }; StringMapList = new List <StringMap> { new StringMap { { "a", "aaa" }, { "b", "bbb" } }, null, new StringMap { { "23a", "23423weaaa" } } }; this.String = "kazapzon"; this.StringArray = new string[] { "mox", null, null, "zaporojets", "kefal" }; this.StringList = new List <string> { "mox", null, null, "zaporojets", "kefal" }; Int = -7; IntN = -789; IntArray = new int[] { 3, 8, 9, -23, 234, 0 }; IntList = new List <int>() { 0, 1, 4, 8 }; IntNArray = new int?[] { 3, null, 9, -23, 234, 0 }; IntNList = new List <int?>() { 0, 1, null, 8 }; UInt = 7; UIntN = 789; UIntArray = new uint[] { 3, 8, 9, 23, 234, 0 }; UIntList = new List <uint>() { 0, 1, 4, 8 }; UIntNArray = new uint?[] { 3, null, 9, 23, 234, 0 }; UIntNList = new List <uint?>() { 0, 1, null, 8 }; //------------------------------------------------------- Long = -74; LongN = -7893; LongArray = new long[] { 43, 8, 59, -243, 234, 0 }; LongList = new List <long>() { 03, 1, 43, 8 }; LongNArray = new long?[] { 3, null, 9, -23, 2344, 0 }; LongNList = new List <long?>() { 0, 1, null, 58 }; ULong = 78; ULongN = 159; ULongArray = new ulong[] { 3, 5, 19, 23, 24, 0 }; ULongList = new List <ulong>() { 0, 1, 7, 9 }; ULongNArray = new ulong?[] { 3, null, 9, 5, 24, 0 }; ULongNList = new List <ulong?>() { 0, 7, null, 8 }; Short = -4; ShortN = -73; ShortArray = new short[] { 16, 8, 59, -23, 34, 0 }; ShortList = new List <short>() { 0, 3, 1, 4, 8 }; ShortNArray = new short?[] { 3, null, 9, -23, 24, 0 }; ShortNList = new List <short?>() { 0, 4, null, 5 }; UShort = 5; UShortN = 59; UShortArray = new ushort[] { 3, 5, 67, 23, 38, 0 }; UShortList = new List <ushort>() { 0, 1, 5, 9 }; UShortNArray = new ushort?[] { 3, null, 9, 0, 4, 0 }; UShortNList = new List <ushort?>() { 0, 7, null, 8, 9 }; //---- Byte = 15; ByteN = 22; ByteArray = new byte[] { 16, 22, 59, 28, 34, 0 }; ByteList = new List <byte>() { 0, 8, 1, 6, 3 }; ByteNArray = new byte?[] { 3, null, 9, 15, 33, 0 }; ByteNList = new List <byte?>() { 0, 4, null, 5 }; Sbyte = 6; SbyteN = 97; SbyteArray = new sbyte[] { 3, 38, 45, 2, 38, 0 }; SbyteList = new List <sbyte>() { 0, 1, 7, 4 }; SbyteNArray = new sbyte?[] { 3, null, 2, 6, 4, 0 }; SbyteNList = new List <sbyte?>() { 0, 7, null, 8, 9 }; Char = 'a'; CharN = 'c'; CharArray = new char[] { 'b', 'c', 'f' }; CharList = new List <char>() { 'a', 'd', 'e', 'h' }; CharNArray = new char?[] { 'v', 'r', 'u', }; CharNList = new List <char?>() { 'w', 'e', 'r', 't' }; Bool = true; BoolN = false; BoolArray = new bool[] { true, false, false, true }; BoolList = new List <bool>() { true, true, false }; BoolNArray = new bool?[] { false, false, true }; BoolNList = new List <bool?>() { true, false, false }; Float = -8; FloatN = -79; FloatArray = new float[] { 3.89f, 8, 9, -2332.5f, 34, 0 }; FloatList = new List <float>() { 0, 1.3f, 4, 8 }; FloatNArray = new float?[] { 3, null, 9, -23, 234, 0 }; FloatNList = new List <float?>() { 0, 1, null, 8 }; this.Double = -7; DoubleN = -89; DoubleArray = new double[] { 3.2, 8, 9, -3.93, 23, 0 }; DoubleList = new List <double>() { 0.1, 1.7, 4, 8 }; DoubleNArray = new double?[] { 3, null, 9, -23, 234, 0 }; DoubleNList = new List <double?>() { 0, 1, null, 8 }; this.Decimal = 2; DecimalN = 89; DecimalArray = new decimal[] { 7, 8, 9, 3, 234, 0 }; DecimalList = new List <decimal>() { 0, 1, 4, 8 }; DecimalNArray = new decimal?[] { 3, null, 9, -23, 234, 0 }; DecimalNList = new List <decimal?>() { 0, 1, null, 8 }; Timespan = TimeSpan.FromHours(2.45); TimespanN = TimeSpan.FromHours(8.19); TimespanArray = new TimeSpan[] { TimeSpan.FromHours(2.001), TimeSpan.FromHours(4.72) }; TimespanList = new List <TimeSpan>() { TimeSpan.FromHours(12.45), TimeSpan.FromHours(11.09) }; TimespanNArray = new TimeSpan?[] { TimeSpan.FromHours(2.435), null, TimeSpan.FromHours(32.45) }; TimespanNList = new List <TimeSpan?>() { TimeSpan.FromHours(2.45), null, TimeSpan.FromHours(7.401) }; Datetime = new DateTime(1980, 2, 3); DatetimeN = new DateTime(1980, 2, 3); DatetimeArray = new DateTime[] { new DateTime(1980, 2, 3), new DateTime(1980, 2, 3) }; DatetimeList = new List <DateTime>() { new DateTime(1980, 2, 3), new DateTime(1980, 2, 3) }; DatetimeNArray = new DateTime?[] { new DateTime(1980, 2, 3), null, new DateTime(1980, 2, 3) }; DatetimeNList = new List <DateTime?>() { new DateTime(1980, 2, 3), null, new DateTime(1980, 2, 3) }; return(this); }
private void trax() { __threadCount = tbTraxThreads.Text.AsInt(1); __writesSec = tbTraxWrites.Text.AsInt(0); __delSec = tbTraxDeletes.Text.AsInt(0); __payloadVariance = tbTraxVariance.Text.AsInt(0); __payloadType = rbtPerson.Checked ? ptype.Person : rbtPerson2.Checked ? ptype.Person2 : rbtString.Checked ? ptype.String : ptype.ByteArray; var added = 0; while (chkTraxer.Checked && m_Traxers.Count < __threadCount) { var context = new tcontext(); var thread = new Thread( (ctx) => { try { var pps = new PilePointer[4000000]; for (var i = 0; i < pps.Length; i++) { pps[i] = PilePointer.Invalid; } var ppi = 0; var di = 0; while (m_Pile.Running && !((tcontext)ctx).STOP) { var tc = __threadCount; if (tc == 0) { return; } var wc = __writesSec / tc; var dc = __delSec / tc; var w = 0; var d = 0; while (w < wc || d < dc) { if (w < wc) { object payload; if (__payloadType == ptype.Person) { var p = Person.MakeFake(); if (__payloadVariance > 0) { p.BinData = new byte[IntMath.ChangeByRndPct(__payloadVariance, -0.25f)]; } payload = p; } else if (__payloadType == ptype.Person2) { var p = Person2.MakeFake2(); if (__payloadVariance > 0) { p.BinData = new byte[IntMath.ChangeByRndPct(__payloadVariance, -0.25f)]; } payload = p; } else if (__payloadType == ptype.String) { payload = new string(' ', __payloadVariance); } else { payload = new byte[__payloadVariance]; } var pp = m_Pile.Put(payload); pps[ppi] = pp; ppi++; if (ppi == pps.Length) { ppi = 0; } w++; } if (d < dc) { if (di == pps.Length) { di = 0; } var pp = pps[di]; if (pp.Address >= 0) { m_Pile.Delete(pp); pps[di] = PilePointer.Invalid; } d++; di++; } } } } catch (Exception error)//abort etc.. { m_Errors.Enqueue(error.ToMessageWithType()); } }); m_Traxers.Add(context); thread.Start(context); added++; } if (added > 0) { log("{0} added {1} threads".Args(DateTime.Now, added)); } var removed = 0; while ((!chkTraxer.Checked && m_Traxers.Count > 0) || m_Traxers.Count > __threadCount) { m_Traxers[0].STOP = true; m_Traxers.RemoveAt(0); removed++; } if (removed > 0) { log("{0} removed {1} threads".Args(DateTime.Now, removed)); } }
public void TestThreadSafety(int cnt, int tcount, int seconds) { using (var pile = new DefaultPile()) { // pile.SegmentSize = 64 * 1024 * 1024; pile.Start(); var data = new PilePointer[cnt]; for (var i = 0; i < cnt; i++) { data[i] = pile.Put(new byte[0], preallocateBlockSize: Memory.PTR_RAW_BYTE_SIZE + (137 * (i % 17))); } var lst = new List <Task>(); long statRead = 0; long statPut = 0; long statDelete = 0; var sw = Stopwatch.StartNew(); var sd = DateTime.UtcNow; var deleteLock = new object(); for (var i = 0; i < tcount; i++) { lst.Add(Task.Factory.StartNew(() => { while (true) { var now = DateTime.UtcNow; if ((now - sd).TotalSeconds > seconds) { break; } var it = ExternalRandomGenerator.Instance.NextScaledRandomInteger(10, 100); for (var j = 0; j < it; j++) { var pp = data[ExternalRandomGenerator.Instance.NextScaledRandomInteger(0, cnt - 1)]; Aver.IsTrue(pile.Get(pp) is byte[]); Interlocked.Increment(ref statRead); } it = ExternalRandomGenerator.Instance.NextScaledRandomInteger(10, 100); for (var j = 0; j < it; j++) { var pp = data[ExternalRandomGenerator.Instance.NextScaledRandomInteger(0, cnt - 1)]; Aver.IsTrue(pile.Put(pp, new byte[ExternalRandomGenerator.Instance.NextScaledRandomInteger(0, 3791)], link: true)); Interlocked.Increment(ref statPut); } if (ExternalRandomGenerator.Instance.NextScaledRandomInteger(0, 100) > 50 && Monitor.TryEnter(deleteLock)) { try { var newData = (PilePointer[])data.Clone(); it = ExternalRandomGenerator.Instance.NextScaledRandomInteger(0, 10 + (cnt / 2)); var toDelete = new List <PilePointer>(); for (var j = 0; j < it; j++) { var idx = ExternalRandomGenerator.Instance.NextScaledRandomInteger(0, cnt - 1); toDelete.Add(newData[idx]); newData[idx] = pile.Put(new byte[12], preallocateBlockSize: ExternalRandomGenerator.Instance.NextScaledRandomInteger(24, 1024)); } data = newData;//atomic; Thread.Sleep(1000); foreach (var pp in toDelete) { Aver.IsTrue(pile.Delete(pp)); Interlocked.Increment(ref statDelete); } } finally { Monitor.Exit(deleteLock); } } } }, TaskCreationOptions.LongRunning)); } Task.WaitAll(lst.ToArray()); var el = sw.ElapsedMilliseconds; Console.WriteLine("Read {0:n0} at {1:n0} ops/sec".Args(statRead, statRead / (el / 1000d))); Console.WriteLine("Put {0:n0} at {1:n0} ops/sec".Args(statPut, statPut / (el / 1000d))); Console.WriteLine("Deleted {0:n0} at {1:n0} ops/sec".Args(statDelete, statDelete / (el / 1000d))); for (var i = 0; i < data.Length; i++) { Aver.IsTrue(pile.Delete(data[i])); } Aver.AreEqual(0, pile.ObjectCount); Aver.AreEqual(0, pile.ObjectLinkCount); Aver.AreEqual(0, pile.AllocatedMemoryBytes); } }
private void clearAll() { clearItem(m_Root); m_Root = default(PilePointer); }
private void trax() { __threadCount = tbTraxThreads.Text.AsInt(1); __writesSec = tbTraxWrites.Text.AsInt(0); __delSec = tbTraxDeletes.Text.AsInt(0); __payloadVariance = tbTraxVariance.Text.AsInt(0); var added = 0; while (chkTraxer.Checked && m_Traxers.Count < __threadCount) { var context = new tcontext(); var thread = new Thread( (ctx) => { try { var pps = new PilePointer[2000000]; for (var i = 0; i < pps.Length; i++) { pps[i] = PilePointer.Invalid; } var ppi = 0; var di = 0; while (m_Pile.Running && !((tcontext)ctx).STOP) { var tc = __threadCount; if (tc == 0) { return; } var wc = __writesSec / tc; var dc = __delSec / tc; var w = 0; var d = 0; while (w < wc || d < dc) { if (w < wc) { var obj = Person.MakeFake(); if (__payloadVariance > 0) { obj.BinData = new byte[__payloadVariance]; } var pp = m_Pile.Put(obj); pps[ppi] = pp; ppi++; if (ppi == pps.Length) { ppi = 0; } w++; } if (d < dc) { if (di == pps.Length) { di = 0; } var pp = pps[di]; if (pp.Address >= 0) { m_Pile.Delete(pp); pps[di] = PilePointer.Invalid; } d++; di++; } } Thread.Sleep(90 + ExternalRandomGenerator.Instance.NextScaledRandomInteger(0, 20)); } } catch (Exception error)//abort etc.. { m_Errors.Enqueue(error.ToMessageWithType()); } }); m_Traxers.Add(context); thread.Start(context); added++; } if (added > 0) { log("{0} added {1} threads".Args(DateTime.Now, added)); } var removed = 0; while ((!chkTraxer.Checked && m_Traxers.Count > 0) || m_Traxers.Count > __threadCount) { m_Traxers[0].STOP = true; m_Traxers.RemoveAt(0); removed++; } if (removed > 0) { log("{0} removed {1} threads".Args(DateTime.Now, removed)); } }
private void trax() { __threadCount = tbTraxThreads.Text.AsInt(1); __writesSec = tbTraxWrites.Text.AsInt(0); __delSec = tbTraxDeletes.Text.AsInt(0); __payloadVariance = tbTraxVariance.Text.AsInt(0); var added = 0; while (chkTraxer.Checked && m_Traxers.Count < __threadCount) { var context = new tcontext(); var thread = new Thread( (ctx) => { try { var pps = new PilePointer[2000000]; for(var i=0; i<pps.Length; i++) pps[i] = PilePointer.Invalid; var ppi = 0; var di=0; while(m_Pile.Running && !((tcontext)ctx).STOP) { var tc = __threadCount; if (tc==0) return; var wc = __writesSec / tc; var dc = __delSec / tc; var w=0; var d=0; while(w<wc || d<dc) { if (w<wc) { var obj = Person.MakeFake(); if (__payloadVariance>0) obj.BinData = new byte[__payloadVariance]; var pp = m_Pile.Put( obj ); pps[ppi] = pp; ppi++; if (ppi==pps.Length) ppi = 0; w++; } if (d<dc) { if (di==pps.Length) di = 0; var pp = pps[di]; if (pp.Address>=0) { m_Pile.Delete( pp ); pps[di] = PilePointer.Invalid; } d++; di++; } } Thread.Sleep(90+ExternalRandomGenerator.Instance.NextScaledRandomInteger(0, 20)); } } catch(Exception error)//abort etc.. { m_Errors.Enqueue(error.ToMessageWithType()); } }); m_Traxers.Add(context); thread.Start(context); added++; } if (added>0) log("{0} added {1} threads".Args(DateTime.Now, added)); var removed = 0; while ((!chkTraxer.Checked&&m_Traxers.Count>0) || m_Traxers.Count > __threadCount) { m_Traxers[0].STOP = true; m_Traxers.RemoveAt(0); removed++; } if (removed>0) log("{0} removed {1} threads".Args(DateTime.Now, removed)); }