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

logo

Cello High Level C

Examples

Construction & Deletion

var x = new(List, Int);
push(x, $I(32));
push(x, $I(6));

/* <'List' At 0x0000000000414603 [32, 6]> */
show(x);

Element Access

var x = new(List, Float, $F(0.01), $F(5.12));

show(get(x, $I(0))); /* 0.01 */
show(get(x, $I(1))); /* 5.12 */

set(x, $I(0), $F(500.1));
show(get(x, $I(0))); /* 500.1 */

Membership

var x = new(List, Int, $I(1), $I(2), $I(3), $I(4));

show($I(mem(x, $I(1)))); /* 1 */
show($I(len(x)));        /* 4 */

rem(x, $I(3));

show($I(mem(x, $I(3)))); /* 0 */
show($I(len(x)));        /* 3 */
show($I(empty(x)));      /* 0 */

resize(x, 0);

show($I(empty(x)));      /* 1 */

Iteration

var greetings = new(List, String, 
  $S("Hello"), $S("Bonjour"), $S("Hej"));

foreach(greet in greetings) {
  show(greet);
}

List


Linked List

The List type is a linked list data structure. Elements can be added and removed from the list and their memory is allocated and deallocated by the structure. Additionally destructors will be called on objects once removed.

Elements are copied into the List using assign and will initially have zero'd memory.

Lists can provide fast insertion and removal at arbitrary locations although most other operations will be slow due to having to traverse the linked list data structure.

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

Derives

Implements

  • Assignassign
  • Cmpcmp eq neq gt lt ge le
  • Concatappend concat
  • 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
  • Pushpush pop push_at pop_at
  • Resizeresize
  • Showshow look print scan

Back