Libs/TokenizerLib/src/Utils/BytePairComparer.cs
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License. using System; using System.Collections.Generic; namespace PSOpenAI.TokenizerLib.Utils { internal class ByteArrayComparer : IEqualityComparer<byte[]> { public bool Equals(byte[] x, byte[] y) { if (x == null || y == null) { return x == y; } if (x.Length != y.Length) { return false; } for (int i = 0; i < x.Length; i++) { if (x[i] != y[i]) { return false; } } return true; } public int GetHashCode(byte[] bytes) { if (bytes == null) { throw new ArgumentNullException(nameof(bytes)); } int hash = 17; foreach (byte b in bytes) { hash = hash * 31 + b; } return hash; } } } |