The LinkedSet class was created by a call to sano.maps.makeSet(LinkedMap:new()). The set is implemented by storing the elements of the set as the keys in LinkedMap, where all keys simply map to the value 'true'.
Example usage:
> linkedset = function(...) return LinkedSet:make(unpack(arg)) end
> -- above is equivalent to: LinkedSet = sano.makers.linkedset
> s = linkedset(1,2,3,3,4); print(s)
{1, 2, 3, 4}
> print(s == linkedset(4,3,2,1))
true
> print(s == linkedset(1,3,5,7))
false
> print(s:remove(1))
1
> s:addAll(iter.count(10,15)); print(s)
{2, 3, 4, 10, 11, 12, 13, 14, 15}
> s:removeAll(iter.count(2,4)); print(s)
{10, 11, 12, 13, 14, 15}
> print(s:size())
6
make | Creates and returns a new instance of self containing the elements passed in as vararg params. |
new | Returns a new empty LinkedList. |
test | Unit test. |
union | Returns the union of set1 and set2 as a new set. |
contains | Returns true if this map contains a mapping (possibly nil) for the given key. |
hash | Returns the sum of utils.hash(i) for i in set. |
difference | Returns the set that would be created by removing from set1 all elements in intersection(set1,set2). |
toString | Returns a string representation of set. |
addAll | Calls collection:add(e) for each e in iter(iterable). |
HashMap | Table-based implementation of a map with support for user-defined hash functions and nil values. |
contains | Returns true if this map contains a mapping (possibly nil) for the given key. |
containsAll | Returns true iff collection:contains(e) for e in iter(iterable). |
containsAny | Returns true if for collection:contains(e) for some e in iter(iterable). |
difference | Returns the set that would be created by removing from set1 all elements in intersection(set1,set2). |
enum | Decorates another iteration to return the index of each element returned from the decorated iteration. |
get | Returns the value stored against key, or nil if no no such value exists. |
intersection | Computes and returns the intersection of set1 and set2. |
iter | Returns an iterator over the key-value pairs in this map in the same order in which they were inserted. |
difference | Returns the set that would be created by removing from set1 all elements in intersection(set1,set2). |
removeAll | Equivalent to calling set:remove(e) for e in iter(elements). |
removeElement | Equivalent to set:remove(element). |
retainOnly | Removes all elements from set which do not also appear in elements. |
size | Returns the number of key-value pairs in this LinkedMap. |
union | Returns the union of set1 and set2 as a new set. |
uniqueFilter | Create and return a uniqueness filter based on set. |
valIter | Equivalent to Map:iter() except that iteration steps return elements in the order val,key instead of key,val. |
xor | Returns the set of elements which appear in either set1 or set2, but not in both. |
collections.make(self, ...)If #args is 1, the argument is assumed to be iterable and its elements are added to the Collection.
Example, assuming Collection is a sequence type:
> print( Collection:make(1,2,3,4) ) [1, 2, 3, 4] > print( Collection:make(iter.count(4) ) [1, 2, 3, 4] > v = Collection:make(1,2,3,4); print( Collection:make(v) ) [1, 2, 3, 4]
This method is used as the make method for LinkedList, SkipVector, HashSet, SkipSet, QueueVector, and PairingHeap. It assumes that self has new() and addAll() methods.
LinkedMap:new(mapImpl)
LinkedSet:test()
sets.union(set1, set2 [, setType])The returned set is created by a call to:
(setType or getmetatable(set1)):make(...)
synonyms: __add
LinkedMap:contains(key)
sets.hash(set)This is the hash function used by all set implementations.
sets.difference(set1, set2 [,setType])The returned set is created by a call to:
(setType or getmetatable(set1)):new()
synonyms: __sub, minus
sets.toString(set)The order in which elements appear in the representation is the same as the iteration order of elements of the set.
Example:
> print(HashSet:make(1,1,3,2,5,6,4))
{1, 2, 3, 4, 5, 6}
collections.addAll(collection, iterable)
LinkedMap:contains(key)
collections.containsAll(collection, elements)
collections.containsAny(collection, iterable)
sets.difference(set1, set2 [,setType])The returned set is created by a call to:
(setType or getmetatable(set1)):new()
synonyms: __sub, minus
iter.enum(iterable [, size, stop, step])If iterable is an object with a size() method, or if size is explicitly specified, the iteration will halt after iterable:size() steps. Otherwise, the iteration halts as soon as iter(iterable) halts (this may be undesireable if the iteration is expected to contain nil values)
If 2 args are given the indices will range from 1 to arg[2]. If 3 args are given the second and third arguments are interpreted as a counting range for the enumeration; If a 4th argument is specified, args 2 and 3 specify the counting range, and arg 4 specifies the step increment.
Examples:
> for ind,v in vector("abcd"):enum() do print(ind,v) end
1 a
2 b
3 c
4 d
> vec = vector("abc"); vec:add(nil)
> for ind,v in vec:enum() do print(ind, v) end
1 a
2 b
3 c
4 nil
LinkedMap:get(key)If the value of nil is explicitly stored against key, then get(key) will return nil and contains(key) will return true.
synonym: __call So, m:get("h") == m("h")
sets.intersection(set1, set2 [, setType])The returned set is created by a call to:
(setType or getmetatable(set1)):new()
LinkedMap:iter()Each step in the iteration returns two values.
sets.difference(set1, set2 [,setType])The returned set is created by a call to:
(setType or getmetatable(set1)):new()
synonyms: __sub, minus
sets.removeAll(set, elements)
sets.removeElement(set, element)In a sequence, the remove() method takes as input an index while the removeElement method takes as input the element to be removed. This method has the same semantics across both set and sequence implementations.
sets.retainOnly(set, elements)If elements is also a set, s, set is modified to be the intersection of set and s.
LinkedMap:size()key-value pairs with a nil value are included in the count.
sets.union(set1, set2 [, setType])The returned set is created by a call to:
(setType or getmetatable(set1)):make(...)
synonyms: __add
sets.uniqueFilter(set)The filter is a function which returns true only for objects it has not yet seen. This can be used in conjuction with iter.filter. For example:
> v = vector(1,1,1,2,3,3,4,1,5,5) > print(vector(iter.filter(v, HashSet:uniqueFilter()))) [1, 2, 3, 4, 5]
Map:valIter()
sets.xor(set1, set2 [,setType])This operation is also often called the symmetric set difference.