private unsafe void InsertAndReadAction(ConcurrentHashmapOfKeys map, ExpandableArrayOfKeys keys, ulong first, ulong count, ulong offset) { var watch = Stopwatch.StartNew(); for (var i = first; i < first + count; i++) { ulong val = 0; if (!map.TryAdd(keys.GetAt(i - offset), i)) { throw new Exception("Failed to insert " + i + ", offset from " + offset); } if (!map.TryGetValue(keys.GetAt(i - offset), ref val)) { throw new Exception("Failed to get at " + i + ", offset from " + offset); } if (val != i) { throw new Exception("Failed to validate at " + i + ", offset from " + offset); } //Console.WriteLine("Added {0} at {1}", val, i); } watch.Stop(); //Console.WriteLine("Elapsed: {0}, for {1}, {2}", watch.ElapsedMilliseconds, first, count); }
/// <summary> /// Will try to add a new document key and expand all column containers to make sure they can fit a new value. /// Returns false for duplicate keys or insufficient resources. /// </summary> public void TryAddDocument(byte[] key, out int index) { index = 0; if (DocumentIdToIndex.TryGetValueInt32(key, ref index)) { OnUpdateValueDocumentsKeyIndex(index); return; } // make a copy of the key (so that we don't introduce dependency on caller's local variables) // and reserve a new index value var newCount = Interlocked.Increment(ref m_untrimmedDocumentCount); if (newCount == int.MinValue) { // if we overflowed over max integer value, put max value back and throw Interlocked.CompareExchange(ref m_untrimmedDocumentCount, int.MaxValue, newCount); throw new Exception("Cannot expand storage any more"); } index = newCount - 1; ExpandStorage(newCount); // now set values at the reserved index if (!DocumentKeys.TrySetAt(index, key)) { throw new Exception("Failed to store new key value at " + index); } if (DocumentIdToIndex.TryAdd(DocumentKeys.GetIntPtrAt(index), index)) { // mark document as valid, but don't touch any of its fields ValidDocumentsBitmap.SafeSet(index); } else { // seems like somebody slipped in and inserted the same value // mark our own generated index value as invalid ValidDocumentsBitmap.SafeClear(index); // now get "their" index and proceed to updating same record // some user data race is possible here, but container state won't be broken index = DocumentIdToIndex.GetInt32At(key); } }
private unsafe void BasicMemoryAction(ConcurrentHashmapOfKeys map, ExpandableArrayOfKeys keys, ulong first, ulong count, ulong offset) { for (var k = first; k < first + count; k++) { using (var map2 = new ConcurrentHashmapOfKeys(_pool)) { map2.TryAdd(keys.GetAt(0), 0); } } //var b = stackalloc void*[(int)100000]; //for (var k = 0; k < 10000000000; k++) //{ // for (var i = 0; i < 100000; i++) // { // b[i] = _pool.Alloc((ulong) i % 10000); // } // for (var i = 0; i < 100000; i++) // { // _pool.Free(b[i]); // } //} }
private unsafe void BasicMemoryAction(ConcurrentHashmapOfKeys map, ExpandableArrayOfKeys keys, ulong first, ulong count, ulong offset) { for (var k = first; k < first + count; k++) { using (var map2 = new ConcurrentHashmapOfKeys(_pool)) { map2.TryAdd(keys.GetAt(0), 0); } } //var b = stackalloc void*[(int)100000]; //for (var k = 0; k < 10000000000; k++) //{ // for (var i = 0; i < 100000; i++) // { // b[i] = _pool.Alloc((ulong) i % 10000); // } // for (var i = 0; i < 100000; i++) // { // _pool.Free(b[i]); // } //} }
private unsafe void InsertAndReadAction(ConcurrentHashmapOfKeys map, ExpandableArrayOfKeys keys, ulong first, ulong count, ulong offset) { var watch = Stopwatch.StartNew(); for (var i = first; i < first + count; i++) { ulong val = 0; if (!map.TryAdd(keys.GetAt(i - offset), i)) { throw new Exception("Failed to insert " + i + ", offset from " + offset); } if (!map.TryGetValue(keys.GetAt(i - offset), ref val)) { throw new Exception("Failed to get at " + i + ", offset from " + offset); } if (val != i) { throw new Exception("Failed to validate at " + i + ", offset from " + offset); } //Console.WriteLine("Added {0} at {1}", val, i); } watch.Stop(); //Console.WriteLine("Elapsed: {0}, for {1}, {2}", watch.ElapsedMilliseconds, first, count); }