« Home » « Learn » « Download » « Github »

logo

Cello High Level C

Methods

hash

uint64_t hash(var self);

Get the hash value for the object self.

hash_data

uint64_t hash_data(void* data, size_t num);

Hash num bytes pointed to by data using Murmurhash.

Examples

Usage

println("%li", $I(hash($I(  1)))); /*   1 */
println("%li", $I(hash($I(123)))); /* 123 */

/* 866003103 */
println("%li", $I(hash_data($I(123), size(Int))));

println("%li", $I(hash($S("Hello"))));  /* -1838682532 */
println("%li", $I(hash($S("There"))));  /*   961387266 */
println("%li", $I(hash($S("People")))); /*   697467069 */

Hash


Hashable

The Hash class provides a mechanism for hashing an object. This hash value should remain the same across objects that are also considered equal by the Cmp class. For objects that are not considered equal this value should aim to be evenly distributed across integers.

This is not a cryptographic hash. It is used for various objects or data structures that require fast hashing such as the Table type. Due to this it should not be used for cryptography or security.

By default an object is hashed by using its raw memory with the Murmurhash algorithm. Due to the link between them it is recommended to only override Hash and Cmp in conjunction.

Definition

struct Hash {
  uint64_t (*hash)(var);
};

Derivers

  • Box |     Unique Pointer
  • Exception |     Exception Object
  • File |     Operating System File
  • Filter |     Filtered Iterable
  • Function |     Function Object
  • GC |     Garbage Collector
  • Map |     Apply Function to Iterable
  • Mutex |     Mutual Exclusion Lock
  • Process |     Operating System Process
  • Range |     Integer Sequence
  • Ref |     Shared Pointer
  • Slice |     Partial Iterable
  • Zip |     Multiple Iterator

Implementers

  • Array |     Sequential Container
  • Float |     Floating Point Object
  • Int |     Integer Object
  • List |     Linked List
  • String |     String Object
  • Table |     Hash table
  • Thread |     Concurrent Execution
  • Tree |     Balanced Binary Tree
  • Tuple |     Basic Collection
  • Type |     Metadata Object

Back