public IEnumerable <ulong> FindRefs(ulong targetObj) { var result = new HashSet <ulong>(); int targetChunk = _startOfChunkToChunkId[StartOfChunk(targetObj)]; int[] referencingChunks; if (!_chunkToReferencingChunks.TryGetValue(targetChunk, out referencingChunks)) { return(result); } foreach (var chunkId in referencingChunks) { ulong firstObj = _chunkIdToFirstNonFreeObjectInChunk[chunkId]; for (ulong current = firstObj; current != 0 && current < firstObj + ((ulong)_chunkSize - firstObj % (ulong)_chunkSize); current = _heap.NextObject(current)) { var type = _heap.GetObjectType(current); if (type == null || type.IsFree) { continue; } type.EnumerateRefsOfObject(current, (child, _) => { if (child == targetObj) { result.Add(current); } }); } } return(result); }
/// <summary> /// Returns the object after this one on the segment. /// </summary> /// <param name="obj">The object to find the next for.</param> /// <returns>The next object on the segment, or 0 if the object was the last one on the segment.</returns> /// <inheritdoc /> public ulong NextObject(ulong obj) => Heap.NextObject(obj);