Macaulay2 Engine
Loading...
Searching...
No Matches
monhashtable.hpp
Go to the documentation of this file.
1// Copyright 2005-2021 Michael E. Stillman
2
3#ifndef _monhashtable_h_
4#define _monhashtable_h_
5
42
43#include <memory> // for unique_ptr
44#include "f4/moninfo.hpp" // for MonomialInfo
45#include "schreyer-resolution/res-moninfo.hpp" // for ResMonoid
46#include "schreyer-resolution/res-monomial-types.hpp" // for res_packed_mon...
47
61{
62 public:
64 long hash_value(value m) const { return m[0] + m[1]; }
65 bool is_equal(value m, value n) const { return mMonoid.is_equal(m, n); }
66 void show(value m) const { mMonoid.show(m); }
68 private:
70};
71
84{
85 public:
87 long hash_value(value m) const { return m[0]; }
88 bool is_equal(value m, value n) const
89 {
90 return mMonoid.monomial_part_is_equal(m, n);
91 }
92 void show(value m) const { mMonoid.show(m); }
94 private:
96};
97
111{
112 public:
114 int hash_value(value m) const
115 {
116 return mMonoid.hash_value(m) + 34141 * mMonoid.get_component(m);
117 } // m[0] + m[1]
118 bool is_equal(value m, value n) const { return mMonoid.is_equal(m, n); }
119 void show(value m) const { mMonoid.show(m); }
121 private:
123};
124
136{
137 public:
139 int hash_value(value m) const { return m[0]; }
140 bool is_equal(value m, value n) const
141 {
142 return mMonoid.monomial_part_is_equal(m, n);
143 }
144 void show(value m) const { mMonoid.show(m); }
146 private:
148};
149
150// ValueType must implement the following:
151// values should have computed hash values stored with them
152// typename ValueType::value
153// long ValueType::hash_value(value m)
154// bool ValueType::is_equal(value m, value n)
155// void ValueType::show(value m) -- prints to stderr
156
157template <typename ValueType>
159{
160 typedef typename ValueType::value value;
161
162 private:
163 const ValueType* M;
164 std::unique_ptr<value[]> hashtab;
165
166 unsigned long size;
167 unsigned int logsize;
168 unsigned long hashmask;
169 unsigned long threshold;
170
171 unsigned long count;
172
173 unsigned long nfind_or_insert;
174 unsigned long nclashes;
175 unsigned long max_run_length;
176 unsigned long monequal_count;
177 unsigned long monequal_fails;
178
179 void insert(value m);
180 void grow(); // Increase logsize by 1, remake hashtab.
181 void initialize(int logsize0);
182
183 public:
184 MonomialHashTable(const ValueType* M0, int logsize = 24);
185 // The hash table size will be a power of 2, and this
186 // is the initial power.
187
189
190 void reset();
191 // Clear out the hash table, resetting all values to 0, and
192 // all counting values back to 0 (count,nclashes,max_run_length)
193 // BUT: the size is kept the same.
194
195 bool find_or_insert(value m, value& result);
196 // If the pointer m is in the hashtable already, then return true,
197 // set result to the already existing pointer. If m is not yet in
198 // the hashtable, insert it, set result to be m, and return false;
199
200 void dump() const;
201 // displays on stderr some info about the hash table
202 // and number of values
203
204 void show() const;
205 // displays the hash table
206 // and then each value is displayed, with hash value.
207 // in form [loc, hash, value]
208};
209#endif
210
211// Local Variables:
212// compile-command: "make -C $M2BUILDDIR/Macaulay2/e "
213// indent-tabs-mode: nil
214// End:
unsigned int logsize
unsigned long monequal_count
std::unique_ptr< value[]> hashtab
unsigned long size
MonomialHashTable(const ValueType *M0, int logsize=24)
unsigned long nclashes
unsigned long threshold
unsigned long monequal_fails
const ValueType * M
void initialize(int logsize0)
ValueType::value value
bool find_or_insert(value m, value &result)
unsigned long count
unsigned long max_run_length
void insert(value m)
unsigned long nfind_or_insert
unsigned long hashmask
Per-ring monomial layout / encoding helper used by F4GB.
Definition moninfo.hpp:108
bool is_equal(value m, value n) const
long hash_value(value m) const
void show(value m) const
MonomialsIgnoringComponent(const MonomialInfo &MI)
const MonomialInfo & mMonoid
packed_monomial value
long hash_value(value m) const
void show(value m) const
MonomialsWithComponent(const MonomialInfo &MI)
bool is_equal(value m, value n) const
const MonomialInfo & mMonoid
ResMonomialsIgnoringComponent(const ResMonoid &MI)
bool is_equal(value m, value n) const
ResMonomialsWithComponent(const ResMonoid &MI)
res_packed_monomial value
bool is_equal(value m, value n) const
int hash_value(value m) const
const ResMonoid & mMonoid
void show(value m) const
VALGRIND_MAKE_MEM_DEFINED & result(result)
monomial_word * packed_monomial
Definition moninfo.hpp:78
MonomialInfo — F4's packed_monomial encoding plus operations.
ResMonoidDense ResMonoid
ResMonoid dispatcher — single typedef switch between ResMonoidDense and ResMonoidSparse.
res_monomial_word * res_packed_monomial
Typed-monomial vocabulary shared by ResMonoid, ResPolyRing, SchreyerFrame, and F4Res.