Пример #1
0
		public bool StartsWith(MemorySlice other)
		{
			if (KeyLength < other.KeyLength)
				return false;
			
            return CompareData(other, other.KeyLength) == 0;
		}
Пример #2
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;
		}
Пример #3
0
		public ushort FindPrefixSize(MemorySlice other)
		{
			_matchedBytes = 0;

			if (_matchPrefixInstance == null)
				_matchPrefixInstance = MatchPrefix;

			CompareData(other, _matchPrefixInstance, Math.Min(KeyLength, other.KeyLength));

			return _matchedBytes;
		}
Пример #4
0
        public ushort FindPrefixSize(MemorySlice other)
        {
            _matchedBytes = 0;

            if (_matchPrefixInstance == null)
            {
                _matchPrefixInstance = MatchPrefix;
            }

            CompareData(other, _matchPrefixInstance, Math.Min(KeyLength, other.KeyLength));

            return(_matchedBytes);
        }
Пример #5
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);
        }
Пример #6
0
        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;
        }
Пример #7
0
        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;
        }
Пример #8
0
        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;
            }
        }
Пример #9
0
        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);
        }
Пример #10
0
        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());
        }
Пример #11
0
        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());
        }
Пример #12
0
        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());
        }
Пример #13
0
        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());
		}      
Пример #14
0
        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;
        }
Пример #15
0
        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());
        }
Пример #16
0
		public bool Equals(MemorySlice other)
		{
			return Compare(other) == 0;
		}
Пример #17
0
		protected abstract int CompareData(MemorySlice other, SliceComparer cmp, ushort size);
Пример #18
0
		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;
			}
		}
Пример #19
0
		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());
		}
Пример #20
0
 protected abstract int CompareData(MemorySlice other, SliceComparer cmp, ushort size);
Пример #21
0
 public bool Equals(MemorySlice other)
 {
     return(Compare(other) == 0);
 }