up: SET     index Zimbu documentation

CLASS T.set<Tkey> @public

summary

     

The builtin type set.

Sets keep a flag for each item that is present. It's like a dict without a value.

Example:

 set<string> s = ["one", "two", "three"]    # initialized from a list
 s.add("yes")
 s.remove("yes")
 IO.print("set has yes: " .. s.has("yes"))

The item type can be int, string, bool, status and any class that has a public ToString() method.

NEW() @public  Create a new empty set.
NEW(keys) @public  Create a new set from a list of items.
$Size() int @public  Return the number of items in the set.
$copy() Set<Tkey> @public  Return a shallow copy of the set.
$ToString() string @public  Return a string representation of the set.
$Iterator() I.Iterator<Tkey> @file  Return an iterator to iterate over all the keys.
$has(key) bool @public  Check if an item is present in the set.
$keys() list<Tkey> @public  Return a list with all the keys.
$add(key) Set<Tkey> @public  Add an item to the set.
$addSet(other) Set<Tkey> @public  Add all items in other to the set.
$addList(keys) Set<Tkey> @public  Add a list of items to the set.
$set(key) Set<Tkey> @public  Add an item to the set if not yet present.
$setSet(other) Set<Tkey> @public  Add all items in other to the set if not yet present.
$setList(keys) Set<Tkey> @public  Add all items in the list keys to the set if not yet present.
$remove(key) Tkey @public  Remove an item from the set.
$removeSet(other) Set<Tkey> @public  Remove all items from the set that are in other.
$removeNotInSet(other) Set<Tkey> @public  Remove all items from the set that are not in other.
$clear() Set<Tkey> @public  Make the set empty.
$clear(key) Set<Tkey> @public  Remove an item from the set if present.
$union(set) Set<Tkey> @public  Make a copy of the set and all items in set if not yet present.
$intersection(other) Set<Tkey> @public  Find all items present both in this set and other.
$difference(other) Set<Tkey> @public  Find items that are not present in other.
 

members (alphabetically)

     

PROC NEW() @public

     

Create a new empty set.

PROC NEW(list<Tkey> keys) @public

     

Create a new set from a list of items.

FUNC $Iterator() I.Iterator<Tkey> @file

     

Return an iterator to iterate over all the keys.

FUNC $Size() int @public

     

Return the number of items in the set.

FUNC $ToString() string @public

     

Return a string representation of the set.

Looks just like a list of the keys: [key1, key2, key3]

FUNC $add(Tkey key) Set<Tkey> @public

     

Add an item to the set.

Throws an E.KeyExists exception when the item is already present. Use set() to avoid an exception.

Returns the set.

FUNC $addList(list<Tkey> keys) Set<Tkey> @public

     

Add a list of items to the set.

Throws an exception when an item is already present. Use setList() to avoid an exception.

Returns the set.

FUNC $addSet(Set<Tkey> other) Set<Tkey> @public

     

Add all items in other to the set.

Throws an exception when an item is already present. Use setSet() to avoid an exception.

Returns the set.

FUNC $clear() Set<Tkey> @public

     

Make the set empty.

Returns the set.

FUNC $clear(Tkey key) Set<Tkey> @public

     

Remove an item from the set if present.

When the item is not present nothing happens.

Returns the set.

FUNC $copy() Set<Tkey> @public

     

Return a shallow copy of the set.

FUNC $difference(Set<Tkey> other) Set<Tkey> @public

     

Find items that are not present in other.

This is equal to $copy.removeSet(other)

Returns a new set with the result.

FUNC $has(Tkey key) bool @public

     

Check if an item is present in the set.

Returns TRUE or FALSE.

FUNC $intersection(Set<Tkey> other) Set<Tkey> @public

     

Find all items present both in this set and other.

This is equal to $copy.removeNotInSet(other)

Returns a new set with the result.

FUNC $keys() list<Tkey> @public

     

Return a list with all the keys.

FUNC $remove(Tkey key) Tkey @public

     

Remove an item from the set.

Throws an E.KeyNotFound exception if the item is not present.

Returns the item.

FUNC $removeNotInSet(Set<Tkey> other) Set<Tkey> @public

     

Remove all items from the set that are not in other.

What remains is the intersection of the two sets.

Returns the set.

FUNC $removeSet(Set<Tkey> other) Set<Tkey> @public

     

Remove all items from the set that are in other.

If other has items that do not exist in this set then nothing happens.

Returns the set.

FUNC $set(Tkey key) Set<Tkey> @public

     

Add an item to the set if not yet present.

When the item is already present nothing happens.

Returns the set.

FUNC $setList(list<Tkey> keys) Set<Tkey> @public

     

Add all items in the list keys to the set if not yet present.

When the item is already present nothing happens.

Returns the set.

FUNC $setSet(Set<Tkey> other) Set<Tkey> @public

     

Add all items in other to the set if not yet present.

When an item is already present nothing happens.

Returns the set.

FUNC $union(Set<Tkey> set) Set<Tkey> @public

     

Make a copy of the set and all items in set if not yet present.

This is equal to $copy().setSet(set).

Returns the new set.

license

      Copyright 2009 Bram Moolenaar All Rights Reserved.

      Licensed under the Apache License, Version 2.0. See the LICENSE file or obtain a copy at: http://www.apache.org/licenses/LICENSE-2.0