- unsigned Hash;
-
- //===----------------------------------------------------===//
- // Profiling or FoldingSet.
- //===----------------------------------------------------===//
-
-private:
-
- static inline
- unsigned ComputeHash(ImutAVLTree* L, ImutAVLTree* R, value_type_ref V) {
- FoldingSetNodeID ID;
-
- if (L) ID.AddInteger(L->ComputeHash());
- ImutInfo::Profile(ID,V);
-
- // Compute the "intermediate" hash. Basically, we want the net profile to
- // be: H(H(....H(H(H(item0),item1),item2)...),itemN), where
- // H(item) is the hash of the data item and H(hash,item) is a hash
- // of the last item hash and the the next item.
-
- unsigned X = ID.ComputeHash();
-
- if (R) {
- ID.clear();
- ID.AddInteger(X);
- ID.AddInteger(R->ComputeHash());
- X = ID.ComputeHash();
- }
-
- return X;
- }
-
- inline unsigned ComputeHash() {
- if (!isMutable() && Hash) return Hash;
- Hash = ComputeHash(getSafeLeft(), getRight(), getValue());
- return Hash;
- }
-
- /// Profile - Generates a FoldingSet profile for a tree node before it is
- /// created. This is used by the ImutAVLFactory when creating
- /// trees.
- static inline
- void Profile(FoldingSetNodeID& ID, ImutAVLTree* L, ImutAVLTree* R,
- value_type_ref V) {
-
- ID.AddInteger(ComputeHash(L, R, V));
- }
-
-public:
-
- /// Profile - Generates a FoldingSet profile for an existing tree node.
- void Profile(FoldingSetNodeID& ID) {
- ID.AddInteger(ComputeHash());
- }