MCPcopy Create free account
hub / github.com/beefytech/Beef / Insert

Method Insert

BeefySysLib/util/HashSet.h:343–393  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

341 }
342
343 bool Insert(const TKey& key, bool add, TKey** keyPtr)
344 {
345 if (mBuckets == NULL) Initialize(0);
346 int_cosize hashCode = (int_cosize)BeefHash<TKey>()(key) & 0x7FFFFFFF;
347 int_cosize targetBucket = hashCode % (int_cosize)mAllocSize;
348
349 for (int_cosize i = mBuckets[targetBucket]; i >= 0; i = mEntries[i].mNext)
350 {
351 if ((mEntries[i].mHashCode == hashCode) && (*(TKey*)&mEntries[i].mKey == key))
352 {
353 if (add)
354 {
355 BF_FATAL("Duplicate key");
356 //ThrowUnimplemented();
357 //ThrowHelper.ThrowArgumentException(ExceptionResource.Argument_AddingDuplicate);
358 }
359 //entries[i].value = value;
360 //mVersion++;
361 if (keyPtr != NULL)
362 *keyPtr = (TKey*)&mEntries[i].mKey;
363 return false;
364 }
365 }
366 int_cosize index;
367 if (mFreeCount > 0)
368 {
369 index = mFreeList;
370 mFreeList = mEntries[index].mNext;
371 mFreeCount--;
372 }
373 else
374 {
375 if (mCount == mAllocSize)
376 {
377 Resize();
378 targetBucket = hashCode % (int_cosize)mAllocSize;
379 }
380 index = mCount;
381 mCount++;
382 }
383
384 mEntries[index].mHashCode = hashCode;
385 mEntries[index].mNext = mBuckets[targetBucket];
386 new (&mEntries[index].mKey) TKey(key);
387 mBuckets[targetBucket] = index;
388 //mVersion++;
389
390 if (keyPtr != NULL)
391 *keyPtr = (TKey*)&mEntries[index].mKey;
392 return true;
393 }
394
395 void RemoveIdx(int_cosize bucket, int_cosize i, int_cosize last)
396 {

Callers

nothing calls this directly

Calls 1

ResizeFunction · 0.85

Tested by

no test coverage detected