Repository navigation
OnixLabs.Core.ReadOnlySpanExtensions
Provides extension methods for ReadOnlySpan<byte> and ReadOnlySpan<char> instances, computing content-based hash codes without allocating.
| Namespace | OnixLabs.Core |
| Assembly | OnixLabs.Core.dll (NuGet) |
| Inheritance |
object → ReadOnlySpanExtensions
|
[EditorBrowsable(EditorBrowsableState.Never)]
public static class ReadOnlySpanExtensionsNote This class is decorated with
[EditorBrowsable(EditorBrowsableState.Never)], which keeps the container class itself out of IntelliSense lists while its extension methods remain fully usable on the receiver types. Bring the methods into scope withusing OnixLabs.Core;.
ReadOnlySpanExtensions uses C# 14 extension blocks (extension(ReadOnlySpan<byte> receiver) and extension(ReadOnlySpan<char> receiver)), so the receiver type appears in the block declaration rather than as a this parameter; the signatures shown below are the call-site signatures as consumed by user code.
GetContentHashCode hashes the content of a span rather than its reference, several bytes at a time and without allocating. Spans with equal content produce equal hash codes. Like HashCode, the result is randomised per process and must not be persisted.
The library's byte- and character-backed value types — Base16, Base32, Base58 and Base64, and Hash, Salt, DigitalSignature, PublicKey and SecurityToken in the security packages — compute their GetHashCode results with these methods.
| Method | Returns | Description |
|---|---|---|
GetContentHashCode() (ReadOnlySpan<byte>) |
int |
Gets the content hash code of the bytes in the current span. |
GetContentHashCode() (ReadOnlySpan<char>) |
int |
Gets the ordinal content hash code of the characters in the current span. |
public int GetContentHashCode()Gets the content hash code of the bytes in the current ReadOnlySpan<byte>. Spans with equal content produce equal hash codes. The bytes are hashed several at a time, without allocating. Like HashCode, the result is randomised per process and must not be persisted.
Returns — The content hash code of the bytes in the current span.
using OnixLabs.Core;
ReadOnlySpan<byte> left = [0x01, 0x02, 0x03];
ReadOnlySpan<byte> right = [0x01, 0x02, 0x03];
bool equal = left.GetContentHashCode() == right.GetContentHashCode(); // truepublic int GetContentHashCode()Gets the ordinal content hash code of the characters in the current ReadOnlySpan<char>. Spans with ordinally equal content produce equal hash codes. The characters are hashed several at a time, without allocating. Like HashCode, the result is randomised per process and must not be persisted.
Returns — The ordinal content hash code of the characters in the current span.
using OnixLabs.Core;
int hash = "Hello".AsSpan().GetContentHashCode();ONIXLabs .NET Library · Repository · NuGet · License (Apache-2.0)
Copyright © ONIXLabs 2020. Licensed under the Apache License, Version 2.0.
- Enumeration<T>
- Optional<T>
- OptionalEqualityComparer<T>
- OptionalExtensions
- Result
- Result<T>
- ResultEqualityComparer<T>
- ResultExtensions
- Specification<T>
- Preconditions
- IValueEquatable<T>
- IValueComparable<T>
- IBinaryConvertible
- ISpanBinaryConvertible
- IMemoryBinaryConvertible
- ArrayExtensions
- ComparableExtensions
- DateTimeExtensions
- ISpanParsableExtensions
- ObjectExtensions
- RandomExtensions
- ReadOnlySequenceExtensions
- ReadOnlySpanExtensions
- StringExtensions
- Base16
- Base32
- Base58
- Base64
- IBaseCodec
- IBaseValue
- IBaseValue<T>
- Base16Codec
- Base32Codec
- Base58Codec
- Base64Codec
- Base16FormatProvider
- Base32FormatProvider
- Base58FormatProvider
- Base64FormatProvider
- EncodingExtensions
- ReadOnlySpanExtensions
- StringBuilderExtensions
- BigDecimal
- BigDecimalEqualityComparer
- BigDecimalOrdinalityComparer
- NumberInfo
- NumberInfoEqualityComparer
- NumberInfoOrdinalityComparer
- Int256
- Int512
- UInt256
- UInt512
- Float128
- Float256
- GenericMath
- NumericsExtensions
- ConversionMode
- ScaleMode
- Hash
- NamedHash
- Sha3
- Sha3Hash224
- Sha3Hash256
- Sha3Hash384
- Sha3Hash512
- Sha3Shake128
- Sha3Shake256
- MerkleTree
- MerkleTree<T>
- PrivateKey
- PublicKey
- NamedPrivateKey
- NamedPublicKey
- EcdhPrivateKey
- EcdhPublicKey
- EcdsaPrivateKey
- EcdsaPublicKey
- EddsaPrivateKey
- EddsaPublicKey
- RsaPrivateKey
- RsaPublicKey
- DigitalSignature
- DigitalSignatureAndPublicKey
- Salt
- Secret
- ICryptoPrimitive<T>
- IHashable
- IEcdhPrivateKey
- IEcdsaPrivateKey
- IEddsaPrivateKey
- IRsaPrivateKey
- IPrivateKeyDerivable<T>
- IPrivateKeyExportable
- IPrivateKeyImportable<T>
- IPrivateKeyPemImportable<T>
- IPrivateKeyPkcs8Exportable
- IPrivateKeyPkcs8Importable<T>
- IPrivateKeyPkcs8PemExportable
- IPrivateKeyRawExportable
- IPrivateKeyRawImportable<T>
- IPrivateKeyRawPemExportable
- IEcdhPublicKey
- IEcdsaPublicKey
- IEddsaPublicKey
- IRsaPublicKey
- IPublicKeyExportable
- IPublicKeyImportable<T>
- IPublicKeyPemExportable
- IPublicKeyPemImportable<T>
- IPublicKeyRawExportable
- IPublicKeyRawImportable<T>
- HashAlgorithmExtensions
- ReadOnlySpanExtensions