Slice.Comparer

Namespace: System · class

Implements: IComparer<Slice>, IEqualityComparer<Slice>, IComparer<KeyValuePair<Slice, Slice>>

Performs optimized equality and comparison checks on Slices

Methods

Compare

int Compare(Slice x, Slice y)

Lexicographically compare two slices and returns an indication of their relative sort order.

  • x — Slice compared with y
  • y — Slice compared with x

Returns: Returns a NEGATIVE value if x is LESS THAN y, ZERO if x is EQUAL TO y, and a POSITIVE value if x is GREATER THAN y.

If both x and y are nil or empty, the comparison will return ZERO. If only y is nil or empty, it will return a NEGATIVE value. If only x is nil or empty, it will return a POSITIVE value.

There are no guarantees that non-zero results will be exactly -1 or +1. You should always use comparison operators or the sign of the returned value, instead of testing for equality with -1 or +1.

Equals

bool Equals(Slice x, Slice y)

Checks if two slices are equal.

  • x — Slice compared with y
  • y — Slice compared with x

Returns: true if x and y have the same size and contain the same sequence of bytes; otherwise, false.

GetHashCode

int GetHashCode(Slice obj)

Computes the hash code of a slice

  • obj — A slice

Returns: A 32-bit signed hash coded calculated from all the bytes in the slice

Fields

Default

static readonly Comparer Default

Default instance of the slice comparator