public IHashNode <U, T> this[U node] { get { IHashNode <U, T> hash = base[node]; if (hash != null && hash.Key.Equals(node)) { return(hash); } else { if (this.Key != null) { if (_value != null) { return(this); } else { return(_hash[node]); } } return(this); } } }
public ITreeNode FetchNode(NodeId pointer) { // Fetches the node out of the heap hash array. int hashIndex = CalcHashValue(pointer); IHashNode hashNode = hash[hashIndex]; while (hashNode != null && !hashNode.Id.Equals(pointer)) { hashNode = hashNode.NextHash; } return(hashNode); }
private void PutInHash(IHashNode node) { NodeId nodeId = node.Id; int hashIndex = CalcHashValue(nodeId); IHashNode oldNode = hash[hashIndex]; hash[hashIndex] = node; node.NextHash = oldNode; // Add it to the start of the linked list, if (hashStart != null) { hashStart.Previous = node; } else { hashEnd = node; } node.Next = hashStart; node.Previous = null; hashStart = node; // Update the 'memory_used' variable memoryUsed += node.MemoryAmount; // STATS if (node is TreeBranch) { ++totalBranchNodeCount; } else { ++totalLeafNodeCount; } }
internal void FlushCache() { IList <IHashNode> toFlush = null; // If the memory use is above some limit then we need to flush out some // of the nodes, if (memoryUsed > maxMemoryLimit) { int allNodeCount = totalBranchNodeCount + totalLeafNodeCount; // The number to clean, int toClean = (int)(allNodeCount * 0.30); // Make an array of all nodes to flush, toFlush = new List <IHashNode>(toClean); // Pull them from the back of the list, IHashNode node = hashEnd; while (toClean > 0 && node != null) { toFlush.Add(node); node = node.Previous; --toClean; } } // If there are nodes to flush, if (toFlush != null) { // Read each group and call the node flush routine, // The mapping of transaction to node list Dictionary <TreeSystemTransaction, List <NodeId> > tranMap = new Dictionary <TreeSystemTransaction, List <NodeId> >(); // Read the list backwards, for (int i = toFlush.Count - 1; i >= 0; --i) { IHashNode node = toFlush[i]; // Get the transaction of this node, TreeSystemTransaction tran = node.Transaction; // Find the list of this transaction, List <NodeId> nodeList = tranMap[tran]; if (nodeList == null) { nodeList = new List <NodeId>(toFlush.Count); tranMap.Add(tran, nodeList); } // Add to the list nodeList.Add(node.Id); } // Now read the key and dispatch the clean up to the transaction objects, foreach (KeyValuePair <TreeSystemTransaction, List <NodeId> > pair in tranMap) { TreeSystemTransaction tran = pair.Key; List <NodeId> nodeList = pair.Value; // Convert to a 'NodeId[]' array, NodeId[] refs = nodeList.ToArray(); // Sort the references, Array.Sort(refs); // Tell the transaction to clean up these nodes, tran.FlushNodesToStore(refs); } } }
public void Delete(NodeId pointer) { int hashIndex = CalcHashValue(pointer); IHashNode hashNode = hash[hashIndex]; IHashNode previous = null; while (hashNode != null && !(hashNode.Id.Equals(pointer))) { previous = hashNode; hashNode = hashNode.NextHash; } if (hashNode == null) { throw new InvalidOperationException("Node not found!"); } if (previous == null) { hash[hashIndex] = hashNode.NextHash; } else { previous.NextHash = hashNode.NextHash; } // Remove from the double linked list structure, // If removed node at head. if (hashStart == hashNode) { hashStart = hashNode.Next; if (hashStart != null) { hashStart.Previous = null; } else { hashEnd = null; } } // If removed node at end. else if (hashEnd == hashNode) { hashEnd = hashNode.Previous; if (hashEnd != null) { hashEnd.Next = null; } else { hashStart = null; } } else { hashNode.Previous.Next = hashNode.Next; hashNode.Next.Previous = hashNode.Previous; } // Update the 'memory_used' variable memoryUsed -= hashNode.MemoryAmount; // KEEP STATS if (hashNode is TreeBranch) { --totalBranchNodeCount; } else { --totalLeafNodeCount; } }
private void HashNode(IHashNode node) { int hash_index = CalcHashValue(node.Id); IHashNode old_node = hash[hash_index]; hash[hash_index] = node; node.NextHash = old_node; // Add it to the start of the linked list, if (hashStart != null) { hashStart.Previous = node; } else { hashEnd = node; } node.Next = hashStart; node.Previous = null; hashStart = node; // Update the 'memory_used' variable memoryUsed += node.MemoryAmount; if (node is TreeBranch) { ++totalBranchNodeCount; } else { ++totalLeafNodeCount; } }
public void Delete(long id) { int hash_index = CalcHashValue(id); IHashNode hash_node = hash[hash_index]; IHashNode previous = null; while (hash_node != null && hash_node.Id != id) { previous = hash_node; hash_node = hash_node.NextHash; } if (hash_node == null) { throw new ApplicationException("Node not found!"); } if (previous == null) { hash[hash_index] = hash_node.NextHash; } else { previous.NextHash = hash_node.NextHash; } // Remove from the double linked list structure, // If removed node at head. if (hashStart == hash_node) { hashStart = hash_node.Next; if (hashStart != null) { hashStart.Previous = null; } else { hashEnd = null; } } // If removed node at end. else if (hashEnd == hash_node) { hashEnd = hash_node.Previous; if (hashEnd != null) { hashEnd.Next = null; } else { hashStart = null; } } else { hash_node.Previous.Next = hash_node.Next; hash_node.Next.Previous = hash_node.Previous; } // Update the 'memory_used' variable memoryUsed -= hash_node.MemoryAmount; if (hash_node is TreeBranch) { --totalBranchNodeCount; } else { --totalLeafNodeCount; } }