Skip to content
Sven Bieg edited this page May 22, 2023 · 26 revisions

The most simple Cluster is the list. Items can be inserted and removed in constant low time.
There is no comparable class in the standard-library. A common application could be a flowing text.

Clusters::list<_item_t, _size_t=uint32_t, _group_size=10>

Creation

To create a list You have to specify the item-type.
With standard-settings Your list has 32 bit and a group-size of 10.

Clusters::list<int> list; // Integer-list
Clusters::list<std::string> list; // String-list
Clusters::list<int, uint64_t, 100> list; // Integer-list with 64 bit and a group-size of 100

Access

You can access items by position:

int i=list[0]; // Returns the first item in the list
int i=list.get_at(0); // Same as above
auto count=list.get_count(); // Returns the number of items in the list
bool found=list.contains(1); // Returns if the list contains the value 1
int pos=0; bool found=list.index_of(1, &pos); // Returns the index of the value 1 if present

Modification

int& item=list.append(); // Append and return item
list.append(0); // Append a value of 0
bool added=list.add(0); // Append the value 0 if not present
list.append(0); // Append the value 0 to the list
int& item=list.insert_at(0); // Insert at position 0 and return item
list.insert_at(0, 0); // Insert value 0 at position 0
bool set=list.set_at(0, 0); // Set item at position 0 to 0 if present
bool removed=list.remove(0); // Removes the value 0 if present
bool removed=list.remove_at(0); // Remove item at position 0
list.clear(); // Remove all items

Iteration

Standard-Iteration

for(int i: list)
    std::cout<<i<<"\n"; // Print items to the screen

Reverse-Iteration

for(auto it=list.rbegin(); it.has_current(); it.move_previous())
    std::cout<<*it<<"\n"; // Print items to the screen in reverse order

Modifying while iterating

for(auto it=list.begin(); it.has_current(); )
    {
    if(*it%2==0)
        {
        it.remove_current(); // Remove every even number
        continue;
        }
    it.move_next();
    }
Clone this wiki locally