SDBM Class
Definition
Computes a 32-bit non-cryptographic hash using the SDBM algorithm popularized by the public-domain NDBM database library. This class cannot be inherited.
public sealed class SDBM : NonCryptographicHashAlgorithm
- Inheritance
-
SDBM
- Inherited Members
- Extension Methods
-
NonCryptographicHashAlgorithmExtensions.ComputeHash(NonCryptographicHashAlgorithm, byte[], int, int)NonCryptographicHashAlgorithmExtensions.TryVerifyHash(NonCryptographicHashAlgorithm, byte[], byte[])NonCryptographicHashAlgorithmExtensions.TryVerifyHash(NonCryptographicHashAlgorithm, byte[], string)NonCryptographicHashAlgorithmExtensions.TryVerifyHash(NonCryptographicHashAlgorithm, Stream, byte[])
Remarks
For each input byte, the running hash is updated as
hash = byte + (hash << 6) + (hash << 16) - hash, producing good distribution for short and
medium-length keys at minimal cost.
When to choose SDBM. SDBM is the public-domain hash from the NDBM/SDBM database library and the historical default in many Unix tools - pick it when interoperating with code that has standardized on the SDBM mix, or when a small, dependency-free 32-bit hash is sufficient. Empirically SDBM gives slightly better distribution than Bernstein and ApHash on short keys at the same per-byte cost. For modern hash-table workloads prefer Fnv1a32 (better avalanche, same cost) or MurmurHash3_32 (markedly better distribution on inputs longer than ~16 bytes).
Output and lifecycle. Produces a 32-bit (4-byte) digest in little-endian byte order. GetCurrentHash() is non-destructive; instances are not thread-safe.
important
This algorithm is not cryptographically secure and should not be used for password hashing, digital signatures, or integrity validation in security-sensitive applications.
using Bodu.IO.Hashing;
using Bodu.IO.Hashing.Extensions;
var sdbm = new SDBM();
byte[] digest = sdbm.ComputeHash(System.Text.Encoding.UTF8.GetBytes("dbm-key"));
Constructors
SDBM()
Initializes a new instance of the SDBM class.
public SDBM()
Methods
Append(ReadOnlySpan<byte>)
When overridden in a derived class, appends the contents of source to the data already processed for the current hash computation.
public override void Append(ReadOnlySpan<byte> source)
Parameters
sourceReadOnlySpan<byte>The data to process.
GetCurrentHashCore(Span<byte>)
When overridden in a derived class, writes the computed hash value to destination without modifying accumulated state.
protected override void GetCurrentHashCore(Span<byte> destination)
Parameters
Reset()
When overridden in a derived class, resets the hash computation to the initial state.
public override void Reset()
Applies to
| Product | Versions |
|---|---|
| .NET | 8, 10 |