protected override void Dispose(bool disposing) { if (!this.disposedValue) { if (disposing) { this.MatchingRows.Clear(); foreach (MemoryNode n in this.next) { try { n.Dispose(); } catch (Exception) { } } this.next = Array.Empty <MemoryNode>(); this.parentNode = null; } // TODO: free unmanaged resources (unmanaged objects) and override a finalizer below. // TODO: set large fields to null. this.disposedValue = true; } }
public void TrimNext(DataSourceBuilder sourceBuilder) { if (sourceBuilder is null) { throw new ArgumentNullException(nameof(sourceBuilder)); } if (this.ChildHeader < 0) { throw new Exception(); } foreach (TypelessDataRow row in MatchingRows) { MemoryNode matchNext = next[row[ChildHeader]]; matchNext?.MatchRow(row); } for (int i = 0; i < next.Length; i++) { if (next[i].Matched < sourceBuilder.Settings.Results.MinimumHits) { sourceBuilder.Settings.TrimmedNode?.Invoke(next[i]); this.next[i] = null; } } }
public void AddNext(MemoryNode next, int i) { if (next is null) { throw new ArgumentNullException(nameof(next)); } this.next[i] = next; next.parentNode = this; }
public void RemoveNode(MemoryNode n) { for (int i = 0; i < this.next.Length; i++) { if (this.next[i] == n) { this.next[i] = null; break; } } }
internal SerializationResults Serialize(INodeFileStream lockedNodeFileStream, long ParentOffset = 0) { SerializationResults results = new SerializationResults(lockedNodeFileStream, this, ParentOffset); long thisOffset = results.Single().Offset; //parent 0 - 8 byte childListSize = (byte)(ParentOffset == 0 ? 4 : 2); byte[] toWrite = new byte[DiskNode.NODE_SIZE + childListSize]; ParentOffset.ToInt40Array().CopyTo(toWrite, 0); for (int i = 0; i < 2; i++) { BitConverter.GetBytes(Results[i]).CopyTo(toWrite, 5 + i * 2); } unchecked { toWrite[9] = (byte)Header; } BitConverter.GetBytes(Value).CopyTo(toWrite, 10); toWrite[12] = (byte)ChildHeader; BitConverter.GetBytes(SkipChildren).CopyTo(toWrite, 13); int nCount = ChildCount; byte[] childBytes; if (childListSize == 4) { childBytes = BitConverter.GetBytes(nCount); } else { if (nCount > ushort.MaxValue) { throw new Exception($"Cant not exceed {ushort.MaxValue} children on non-root node"); } else { ushort usCount = (ushort)nCount; childBytes = BitConverter.GetBytes(usCount); } } childBytes.CopyTo(toWrite, DiskNode.NODE_SIZE); lockedNodeFileStream.Write(toWrite); if (nCount > 0) { int skip = (nCount * DiskNode.NEXT_SIZE); long ChildListOffset = lockedNodeFileStream.Offset; byte[] skipBytes = new byte[skip]; lockedNodeFileStream.Write(skipBytes); byte[] nextOffsets = new byte[nCount * DiskNode.NEXT_SIZE]; int i; for (i = 0; i < nCount; i++) { MemoryNode nextn = this.next[i]; byte[] offsetBytes; if (nextn != null) { offsetBytes = lockedNodeFileStream.Offset.ToInt40Array(); } else { offsetBytes = new byte[] { 0, 0, 0, 0, 0 }; } offsetBytes.CopyTo(nextOffsets, i * DiskNode.NEXT_SIZE); if (nextn != null) { results.AddRange(nextn.Serialize(lockedNodeFileStream, thisOffset)); } } long lastOffset = lockedNodeFileStream.Offset; lockedNodeFileStream.Seek(ChildListOffset - childBytes.Length - 5); lockedNodeFileStream.Write(lastOffset.ToInt40Array()); lockedNodeFileStream.Seek(ChildListOffset); lockedNodeFileStream.Write(nextOffsets); lockedNodeFileStream.Seek(lastOffset); } return(results); }