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

◆ find() [2/2]

auto MonomialHashTable< ValueType >::find ( const MonomialView & m,
HashInt mhash )->MonomialIndex

Essentially the previous case when monomial(n) = monomial 1.

Definition at line 83 of file MonomialHashTable.cpp.

84 {
85 mStats.n_calls_find++;
86 if (mMonomialPointers.size() >= mThreshold) grow();
87 auto hash = mhash & mHashMask;
88 long run = 0;
89 while (mBuckets[hash] != 0)
90 {
91 MonomialIndex current = mBuckets[hash];
92 if (mhash == mHashValues[current])
93 {
94 // likely a match. But need to check equality first
95 mStats.monequal_count++;
96 if (m == mMonomialPointers[current]) // this == is a required MonomialView method!
97 {
98 // Already in the table
99 if (run > mStats.max_run_length) mStats.max_run_length = run;
100 return current;
101 }
102 mStats.monequal_fails++;
103 }
104 ++hash;
105 ++run;
106 mStats.n_clashes++;
107 if (hash == mBuckets.size()) hash = 0;
108 }
109 if (run > mStats.max_run_length) mStats.max_run_length = run;
110 mBuckets[hash] = mMonomialPointers.size(); // index of the new element.
111 mMonomialPointers.emplace_back(m, mMonomialSpace);
112 mHashValues.push_back(mhash);
113 return mBuckets[hash];
114 }
std::vector< MonomialView > mMonomialPointers
std::vector< HashInt > mHashValues
std::vector< MonomialIndex > mBuckets
int32_t MonomialIndex

References grow(), mBuckets, mHashMask, mHashValues, mMonomialPointers, mMonomialSpace, mStats, and mThreshold.

Referenced by find(), and TEST().