Macaulay2 Engine
Loading...
Searching...
No Matches
hash.hpp File Reference

EngineObject / MutableEngineObject — shared bases that supply the hash an M2 interpreter object expects. More...

#include "newdelete.hpp"
#include <cassert>
#include <M2/gc-include.h>

Go to the source code of this file.

Classes

class  EngineObject
 Base class for engine objects that are immutable once their hash has been pinned (typically once they cross over to the front end). More...
class  MutableEngineObject
 Base class for engine objects that may mutate, so their hash must be identity-based rather than content-based. More...

Detailed Description

EngineObject / MutableEngineObject — shared bases that supply the hash an M2 interpreter object expects.

Note
AI-generated documentation. Verify against the source before relying on it.

Declares two parallel bases:

  • EngineObject derives from our_new_delete (so allocation routes through bdwgc), supplies a virtual destructor anchor that makes delete base_ptr safe across subclass boundaries, and stores a mutable mHashValue that hash() fills lazily by calling the pure-virtual computeHashValue() on first read. The 0-to-1 bump after the call keeps "not yet computed" distinguishable from a legitimate hash of zero. Subclasses (immutable types like Matrix, FreeModule, ...) implement computeHashValue over their own stable state.
  • MutableEngineObject derives from our_gc_cleanup (so its destructor runs under a GC finaliser) rather than from EngineObject, and takes a different approach to hashing: no lazy cache, no computeHashValue hook. Every instance is assigned a unique sequential id from the static counter mNextMutableHashValue at construction time, and hash() just returns that id — mutating the object never changes it. This is what MutableMatrix and other mutable engine types inherit from.

The hashes are the cache keys M2's interpreter HashTable uses to identify engine objects within a session; std::hash<T> is unsuitable because engine objects are too large to hash in full per lookup.

See also
newdelete.hpp

Definition in file hash.hpp.