27 #include <type_traits>
38 template <
class KeyType,
class ValueType>
49 return ((
char*)&
value) - ((
char*)
this);
54 #define UNUSED 493295393
56 unsigned int newHash(
unsigned int x);
69 template <
class KeyType>
75 return std::hash<U>().
operator()(u);
80 static auto hash_impl(U
const& u,
int) -> decltype(u.hash()) {
103 #define FILL_FACTOR .667
106 #define GET_HASH(data, i) (*((size_t*)(((char*)data) + (i * objSize))))
107 #define GET_HASH_PTR(data, i) ((size_t*)(((char*)data) + (i * objSize)))
108 #define GET_KEY_PTR(data, i) ((void*)(((char*)data) + sizeof(size_t) + (i * objSize)))
109 #define GET_VALUE_PTR(data, i) ((void*)(((char*)data) + valueOffset + (i * objSize)))
110 #define GET_KEY(data, i, type) (*((type*)(((char*)data) + sizeof(size_t) + (i * objSize))))
111 #define GET_VALUE(data, i, type) (*((type*)(((char*)data) + valueOffset + (i * objSize))))
117 template <
class KeyType,
class ValueType>
120 this->disableDestructor = disableOrNot;
123 template <
class KeyType,
class ValueType>
126 return this->disableDestructor;
130 template <
class KeyType,
class ValueType>
148 std::cout <<
"PairArray: setUpAndCopyFrom: keyTypeInfo = 0 " << std::endl;
152 std::cout <<
"PairArray: setUpAndCopyFrom: valueTypeInfo = 0" << std::endl;
170 uint32_t keySize = (toMe.
valueOffset -
sizeof(size_t));
177 uint32_t objSize = toMe.
objSize;
181 for (
int i = 0; i < toMe.
numSlots; i++) {
200 for (
int j = i; j < toMe.
numSlots; j++) {
218 for (
int j = i; j < toMe.
numSlots; j++) {
229 template <
class KeyType,
class ValueType>
231 setUpAndCopyFrom(
this, &toMe);
234 template <
class KeyType,
class ValueType>
241 size_t slot = hashVal % (numSlots - 1);
244 for (
size_t slotsChecked = 0; slotsChecked < numSlots; slotsChecked++) {
249 }
else if (
GET_HASH(data, slot) == hashVal) {
252 if (
GET_KEY(data, slot, KeyType) == me) {
260 if (slot == numSlots - 1)
269 std::cout <<
"in count(): hashVal = " << hashVal <<
", slot = " << slot
270 <<
", numSlots =" << numSlots <<
". Warning: Ran off the end of the hash table!!\n";
275 template <
class KeyType,
class ValueType>
282 size_t slot = hashVal % (numSlots - 1);
285 for (
size_t slotsChecked = 0; slotsChecked < numSlots; slotsChecked++) {
289 std::cout <<
"WARNING: setUnused for an empty slot" << std::endl;
293 }
else if (
GET_HASH(data, slot) == hashVal) {
296 if (
GET_KEY(data, slot, KeyType) == me) {
309 if (slot == numSlots - 1)
318 std::cout <<
"in setUnused(): hashVal = " << hashVal <<
", slot = " << slot
319 <<
", numSlots =" << numSlots <<
". Warning: Ran off the end of the hash table!!\n";
324 template <
class KeyType,
class ValueType>
334 size_t slot = hashVal % (numSlots - 1);
337 for (
size_t slotsChecked = 0; slotsChecked < numSlots; slotsChecked++) {
346 std::cout <<
"Not enough space when in placement new the key type and value type"
354 GET_KEY(data, slot, KeyType) = me;
362 std::cout <<
"Not enough space when inserting new key" << std::endl;
370 }
else if (
GET_HASH(data, slot) == hashVal) {
373 if (
GET_KEY(data, slot, KeyType) == me) {
383 if (slot == numSlots - 1)
392 std::cout <<
"Fatal Error: Ran off the end of the hash table!!\n";
396 template <
class KeyType,
class ValueType>
402 for (
unsigned int pow = 0; pow <= 31; pow++) {
403 if (val >= numSlotsIn) {
414 std::cout <<
"Fatal Error: Bad: could not get the correct size " << numSlotsIn
415 <<
" for the array\n";
424 for (
int i = 0; i <
numSlots; i++) {
429 template <
class KeyType,
class ValueType>
431 return usedSlots >= maxSlots;
434 template <
class KeyType,
class ValueType>
438 keyTypeInfo.setup<KeyType>();
439 valueTypeInfo.setup<ValueType>();
444 valueOffset = temp.getValueOffset();
455 setDisableDestructor(
false);
460 template <
class KeyType,
class ValueType>
463 if (isDestructorDisabled() ==
true) {
467 if (keyTypeInfo.getTypeCode() == 0) {
468 std::cout <<
"PairArray: ~PairArray: keyTypeInfo = 0 " << std::endl;
471 if (valueTypeInfo.getTypeCode() == 0) {
472 std::cout <<
"PairArray: ~PairArray: valueTypeInfo = 0" << std::endl;
475 if (!keyTypeInfo.descendsFromObject() && !valueTypeInfo.descendsFromObject())
479 for (uint32_t i = 0; i < numSlots; i++) {
481 if (keyTypeInfo.descendsFromObject())
482 keyTypeInfo.deleteConstituentObject(
GET_KEY_PTR(data, i));
483 if (valueTypeInfo.descendsFromObject())
484 valueTypeInfo.deleteConstituentObject(
GET_VALUE_PTR(data, i));
489 template <
class KeyType,
class ValueType>
492 uint32_t howMany = numSlots * 2;
496 makeObjectWithExtraStorage<PairArray<KeyType, ValueType>>(objSize * howMany, howMany);
502 for (uint32_t i = 0; i < numSlots; i++) {
510 GET_KEY(data, i, KeyType).~KeyType();
511 GET_VALUE(data, i, ValueType).~ValueType();
520 template <
class KeyType,
class ValueType>
525 template <
class KeyType,
class ValueType>
530 template <
class KeyType,
class ValueType>
536 template <
class KeyType,
class ValueType>
539 : iterateMe(iterateMeIn) {
550 template <
class KeyType,
class ValueType>
553 : iterateMe(iterateMeIn) {
557 template <
class KeyType,
class ValueType>
562 int objSize = iterateMe->objSize;
563 while (slot != iterateMe->numSlots &&
GET_HASH(iterateMe->data, slot) ==
UNUSED)
566 if (slot == iterateMe->numSlots)
570 template <
class KeyType,
class ValueType>
573 int objSize = iterateMe->objSize;
577 template <
class KeyType,
class ValueType>
580 if (!done || !me.
done)
PDBTemplateBase keyTypeInfo
static auto hash_impl(U const &u,...) -> size_t
#define GET_KEY(data, i, type)
#define GET_VALUE(data, i, type)
static auto hash_impl(U const &u, int) -> decltype(u.hash())
size_t getSize(void *forMe)
void deleteObject(void *deleteMe)
int count(const KeyType &which)
void deleter(void *deleteMe, ObjType *dummy)
#define GET_HASH(data, i)
PDBTemplateBase valueTypeInfo
bool operator!=(const PDBMapIterator &me) const
#define GET_KEY_PTR(data, i)
Handle< PairArray< KeyType, ValueType > > doubleArray()
void setUpAndCopyFrom(void *target, void *source) const
unsigned int newHash(unsigned int x)
#define GET_VALUE_PTR(data, i)
int16_t getTypeCode() const
void setUpAndCopyFromConstituentObject(void *target, void *source) const
Handle< PairArray< KeyType, ValueType > > iterateMe
ValueType & operator[](const KeyType &which)
bool isDestructorDisabled()
size_t specialHash(unsigned u)
MapRecordClass< KeyType, ValueType > & operator*()
static auto hash(const KeyType &k) -> decltype(hash_impl(k, 0))
static auto hash_impl(U const &u, int) -> decltype(specialHash(u))
#define GET_HASH_PTR(data, i)
void setDisableDestructor(bool disableOrNot)
bool descendsFromObject() const
void setUnused(const KeyType &clearMe)