public bool StartsWith(MemorySlice other) { if (KeyLength < other.KeyLength) return false; return CompareData(other, other.KeyLength) == 0; }
public int Compare(MemorySlice other) { Debug.Assert(Options == SliceOptions.Key); Debug.Assert(other.Options == SliceOptions.Key); var r = CompareData(other, KeyLength <= other.KeyLength ? KeyLength : other.KeyLength); if (r != 0) return r; return KeyLength - other.KeyLength; }
public ushort FindPrefixSize(MemorySlice other) { _matchedBytes = 0; if (_matchPrefixInstance == null) _matchPrefixInstance = MatchPrefix; CompareData(other, _matchPrefixInstance, Math.Min(KeyLength, other.KeyLength)); return _matchedBytes; }
public ushort FindPrefixSize(MemorySlice other) { _matchedBytes = 0; if (_matchPrefixInstance == null) { _matchPrefixInstance = MatchPrefix; } CompareData(other, _matchPrefixInstance, Math.Min(KeyLength, other.KeyLength)); return(_matchedBytes); }
public int Compare(MemorySlice other) { Debug.Assert(Options == SliceOptions.Key); Debug.Assert(other.Options == SliceOptions.Key); var r = CompareData(other, KeyLength <= other.KeyLength ? KeyLength : other.KeyLength); if (r != 0) { return(r); } return(KeyLength - other.KeyLength); }
public PrefixedSlice(MemorySlice key) { Header = new PrefixedSliceHeader { PrefixId = NonPrefixedId, PrefixUsage = 0, NonPrefixedDataSize = key.KeyLength }; NonPrefixedData = key.ToSlice(); Size = (ushort)(Constants.PrefixedSliceHeaderSize + key.KeyLength); KeyLength = key.KeyLength; Options = SliceOptions.Key; }
public int Compare(MemorySlice other) { Debug.Assert(Options == SliceOptions.Key); Debug.Assert(other.Options == SliceOptions.Key); var srcKey = this.KeyLength; var otherKey = other.KeyLength; var length = srcKey <= otherKey ? srcKey : otherKey; var r = CompareData(other, length); if (r != 0) return r; return srcKey - otherKey; }
public new ushort FindPrefixSize(MemorySlice other) { if (PrefixComparisonCache == null) { return(base.FindPrefixSize(other)); } PrefixComparisonCache.Disabled = true; try { return(base.FindPrefixSize(other)); } finally { PrefixComparisonCache.Disabled = false; } }
public int Compare(MemorySlice other) { Debug.Assert(Options == SliceOptions.Key); Debug.Assert(other.Options == SliceOptions.Key); var srcKey = this.KeyLength; var otherKey = other.KeyLength; var length = srcKey <= otherKey ? srcKey : otherKey; var r = CompareData(other, length); if (r != 0) { return(r); } return(srcKey - otherKey); }
protected override int CompareData(MemorySlice other, ushort size) { var otherSlice = other as Slice; if (otherSlice != null) { return(CompareDataInline(otherSlice, size)); } var prefixedSlice = other as PrefixedSlice; if (prefixedSlice != null) { return(PrefixedSliceComparisonMethods.Compare(this, prefixedSlice, PrefixedSlice.MemoryComparerInstance, size)); } throw new NotSupportedException("Cannot compare because of unknown slice type: " + other.GetType()); }
protected override int CompareData(MemorySlice other, SliceComparer cmp, ushort size) { var prefixedSlice = other as PrefixedSlice; if (prefixedSlice != null) { return(SliceComparisonMethods.Compare(this, prefixedSlice, cmp, size)); } var slice = other as Slice; if (slice != null) { return(SliceComparisonMethods.Compare(slice, this, cmp, size) * -1); } throw new NotSupportedException("Cannot compare because of unknown slice type: " + other.GetType()); }
protected override int CompareData(MemorySlice other, PrefixedSliceComparer cmp, ushort size) { var otherSlice = other as Slice; if (otherSlice != null) { if (Array != null) { fixed(byte *a = Array) { if (otherSlice.Array != null) { fixed(byte *b = otherSlice.Array) { return(cmp(a, b, size)); } } return(cmp(a, otherSlice.Pointer, size)); } } if (otherSlice.Array != null) { fixed(byte *b = otherSlice.Array) { return(cmp(Pointer, b, size)); } } return(cmp(Pointer, otherSlice.Pointer, size)); } var prefixedSlice = other as PrefixedSlice; if (prefixedSlice != null) { return(PrefixedSliceComparisonMethods.Compare(this, prefixedSlice, cmp, size)); } throw new NotSupportedException("Cannot compare because of unknown slice type: " + other.GetType()); }
protected override int CompareData(MemorySlice other, ushort size) { var otherSlice = other as Slice; if (otherSlice != null) return CompareDataInline(otherSlice, size); var prefixedSlice = other as PrefixedSlice; if (prefixedSlice != null) return PrefixedSliceComparisonMethods.Compare(this, prefixedSlice, MemoryUtils.MemoryComparerInstance, size); throw new NotSupportedException("Cannot compare because of unknown slice type: " + other.GetType()); }
protected override int CompareData(MemorySlice other, SliceComparer cmp, ushort size) { var prefixedSlice = other as PrefixedSlice; if (prefixedSlice != null) return SliceComparisonMethods.Compare(this, prefixedSlice, cmp, size); var slice = other as Slice; if (slice != null) { return SliceComparisonMethods.Compare(slice, this, cmp, size) * -1; } throw new NotSupportedException("Cannot compare because of unknown slice type: " + other.GetType()); }
public bool Equals(MemorySlice other) { return Compare(other) == 0; }
protected abstract int CompareData(MemorySlice other, SliceComparer cmp, ushort size);
public new ushort FindPrefixSize(MemorySlice other) { if (PrefixComparisonCache == null) return base.FindPrefixSize(other); PrefixComparisonCache.Disabled = true; try { return base.FindPrefixSize(other); } finally { PrefixComparisonCache.Disabled = false; } }
protected override int CompareData(MemorySlice other, SliceComparer cmp, ushort size) { var otherSlice = other as Slice; if (otherSlice != null) { if (Array != null) { fixed (byte* a = Array) { if (otherSlice.Array != null) { fixed (byte* b = otherSlice.Array) { return cmp(a, b, size); } } return cmp(a, otherSlice.Pointer, size); } } if (otherSlice.Array != null) { fixed (byte* b = otherSlice.Array) { return cmp(Pointer, b, size); } } return cmp(Pointer, otherSlice.Pointer, size); } var prefixedSlice = other as PrefixedSlice; if (prefixedSlice != null) return SliceComparisonMethods.Compare(this, prefixedSlice, cmp, size); throw new NotSupportedException("Cannot compare because of unknown slice type: " + other.GetType()); }
public bool Equals(MemorySlice other) { return(Compare(other) == 0); }