public static bool Equal(BufBase b1, BufBase b2) { if (Object.ReferenceEquals(b1, null) && Object.ReferenceEquals(b2, null)) { return(true); } if (Object.ReferenceEquals(b1, null) || Object.ReferenceEquals(b2, null)) { return(false); } if (Object.ReferenceEquals(b1, b2)) { return(true); } var b1len = b1.BaseArray.Length - b1.BaseArrayOffset; var b2len = b2.BaseArray.Length - b2.BaseArrayOffset; if (b1len != b2len) { return(false); } for (int i = 0; i < b1len; ++i) { if (b1.BaseArray[b1.BaseArrayOffset + i] != b2.BaseArray[b2.BaseArrayOffset + i]) { return(false); } } return(true); }
public static int operator -(BufRef left, BufLen right) { if (!BufBase.SameBuffer(left, right)) { throw new InvalidOperationException("Can only subtract BufRef with the same underlying buffer!"); } return(left.Position - right.BaseArrayOffset); }
bool IEquatable <BufBase> .Equals(BufBase other) { if (Object.ReferenceEquals(other, null)) { return(false); } return(Equal(this, other)); }
bool IEquatable <BufBase> .Equals(BufBase other) { if (other is null) { return(false); } return(Equal(this, other)); }
public static int ComputeHash(BufBase data) { unchecked { const int p = 16777619; int hash = (int)2166136261; for (int i = data.BaseArrayOffset; i < data.BaseArray.Length; ++i) { hash = (hash ^ data.BaseArray[i]) * p; } hash += hash << 13; hash ^= hash >> 7; hash += hash << 3; hash ^= hash >> 17; hash += hash << 5; return(hash); } }
public static int Compare(BufBase b1, BufBase b2) { if (Object.ReferenceEquals(b1, null) && Object.ReferenceEquals(b2, null)) { return(0); } if (Object.ReferenceEquals(b1, null)) { return(-1); } if (Object.ReferenceEquals(b2, null)) { return(1); } if (Object.ReferenceEquals(b1, b2)) { return(0); } var b1len = b1.BaseArray.Length - b1.BaseArrayOffset; var b2len = b2.BaseArray.Length - b2.BaseArrayOffset; for (int i = 0; i < b1len; ++i) { if (b2.BaseArrayOffset + i >= b2.BaseArray.Length) { return(1); } var c = b1.BaseArray[b1.BaseArrayOffset + i] - b2.BaseArray[b2.BaseArrayOffset + i]; if (c != 0) { return(Math.Sign(c)); } } if (b2len > b1len) { return(-1); } return(0); }
public BufLen(BufBase src, int offset, int len) : base(src, offset) { LengthDef = Math.Min(len, src.BaseArray.Length - src.BaseArrayOffset - offset); }
public static bool SameBuffer(BufBase left, BufBase right) { return(ReferenceEquals(left.Data, right.Data)); }
public BufRef(BufBase src, int offset) : base(src, offset) { }
public BufRef(BufBase src) : base(src) { }
int IComparable <BufBase> .CompareTo(BufBase other) { return(Compare(this, other)); }
public BufBase(BufBase src, int offset) { Data = src.Data; StartIx = Position = src.Position + offset; }
public BufBase(BufBase src) { Data = src.Data; StartIx = src.StartIx; Position = src.Position; }
public BufRefLen(BufBase src, int offset) : base(src, offset) { LengthDef = src.BaseArray.Length - src.BaseArrayOffset - offset; }
public BufRefLen(BufBase src) : base(src) { LengthDef = src.BaseArray.Length - src.BaseArrayOffset; }