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

logo

Cello High Level C

Examples

Usage

var prices = new(Table, String, Int);
set(prices, $S("Apple"),  $I(12));
set(prices, $S("Banana"), $I( 6));
set(prices, $S("Pear"),   $I(55));

foreach (key in prices) {
  var price = get(prices, key);
  println("Price of %$ is %$", key, price);
}

Manipulation

var t = new(Table, String, Int);
set(t, $S("Hello"), $I(2));
set(t, $S("There"), $I(5));

show($I(len(t))); /* 2 */
show($I(mem(t, $S("Hello")))); /* 1 */

rem(t, $S("Hello"));

show($I(len(t))); /* 1 */
show($I(mem(t, $S("Hello")))); /* 0 */
show($I(mem(t, $S("There")))); /* 1 */

resize(t, 0);

show($I(len(t))); /* 0 */
show($I(mem(t, $S("Hello")))); /* 0 */
show($I(mem(t, $S("There")))); /* 0 */

Table


Hash table

The Table type is a hash table data structure that maps keys to values. It uses an open-addressing robin-hood hashing scheme which requires Hash and Cmp to be defined on the key type. Keys and values are copied into the collection using the Assign class and intially have zero'd memory.

Hash tables provide O(1) lookup, insertion and removal can but require long pauses when the table must be rehashed and all entries processed.

This is largely equivalent to the C++ construct std::unordered_map

Derives

Implements

  • Assignassign
  • Cmpcmp eq neq gt lt ge le
  • Docname brief description definition
  • Getget set mem rem key_type val_type
  • Hashhash hash_data
  • Iterforeach iter_init iter_next iter_type
  • Lenlen
  • Markmark
  • Newnew del construct destruct
  • Resizeresize
  • Showshow look print scan

Back