Macaulay2 Engine
Loading...
Searching...
No Matches

◆ find_or_insert()

template<typename ValueType>
bool MonomialHashTable< ValueType >::find_or_insert ( value m,
value & result )

Definition at line 83 of file monhashtable.cpp.

84{
85 auto mhash = HASHVALUE(m);
86 auto hashval = mhash & hashmask;
87 if (!hashtab[hashval])
88 {
89 // No entry is there. So, we insert it directly.
90 hashtab[hashval] = m;
91 result = m;
92 count++;
93 if (count > threshold) grow();
94 return false;
95 }
96 else
97 {
98 // Something is there, so we need to find either this value,
99 // or a free spot, whichever comes first.
100 value *hashtop = hashtab.get() + size;
101 for (value *i = hashtab.get() + hashval;; i++)
102 {
103 if (i == hashtop) i = hashtab.get();
104 if (!(*i))
105 {
106 // Spot is empty, so m is a new value
107 *i = m;
108 result = m;
109 count++;
110 if (count > threshold) grow();
111 return false;
112 }
113 // if (HASHVALUE(*i) == mhash)
114 // {
115 if (MONOMIAL_EQUAL(m, *i))
116 {
117 result = *i;
118 return true;
119 }
120 // }
121 }
122 }
123}
std::unique_ptr< value[]> hashtab
unsigned long size
unsigned long threshold
ValueType::value value
unsigned long count
unsigned long hashmask
#define HASHVALUE(m)
#define MONOMIAL_EQUAL(m, n)

References count, grow(), hashmask, hashtab, HASHVALUE, MONOMIAL_EQUAL, result(), size, and threshold.