private long CollectStatistic(HashPage pg, HashStatistic stat, int height) { long totalHeight = 0; stat.nPages += 1; if (++height > stat.maxHeight) { stat.maxHeight = height; } foreach (object child in pg.items) { if (child is HashPage) { totalHeight += CollectStatistic((HashPage)child, stat, height); } else if (child != null) { int collisionChainLength = 0; for (CollisionItem item = (CollisionItem)child; item != null; item = item.next) { collisionChainLength += 1; } if (stat.maxCollisionChainLength < collisionChainLength) { stat.maxCollisionChainLength = collisionChainLength; } stat.nItems += collisionChainLength; stat.nChains += 1; totalHeight += height; } } return(totalHeight); }
public HashStatistic GetStatistic() { HashStatistic stat = new HashStatistic(); if (root != null) { long totalHeight = CollectStatistic(root, stat, 0); if (stat.nChains != 0) { stat.aveHeight = (double)totalHeight / stat.nChains; stat.aveCollisionChainLength = (double)stat.nItems / stat.nChains; } } return(stat); }