105 lines
2.3 KiB
Markdown
105 lines
2.3 KiB
Markdown
Utility Modules
|
|
===============
|
|
|
|
To ensure there are no external dependencies (including chicken eggs),
|
|
these modules re-implement any basic procedures which are required for
|
|
any algorithms used. And some advanced yet generic functionality as
|
|
well.
|
|
|
|
The modules are listed in alphabetical order.
|
|
|
|
### Set (List)
|
|
|
|
(import util-set-list)
|
|
|
|
This module implements linear-time set with custom comparator.
|
|
|
|
(make-lset [comparator])
|
|
|
|
* ```comparator``` - comparison procedure, defaults to ```equal?```
|
|
|
|
Creates new lset with given comparator.
|
|
|
|
(lset? v)
|
|
|
|
* ```v``` - any value
|
|
|
|
Returns ```#t``` if given value is a lset.
|
|
|
|
(lset-empty? ls)
|
|
|
|
* ```ls``` - lset instance
|
|
|
|
Returns ```#t``` if given lset contains no elements.
|
|
|
|
(lset-member? ls el)
|
|
|
|
* ```ls``` - lset instance
|
|
* ```el``` - element to check
|
|
|
|
Returns ```#t``` if given element ```el``` is contained in the lset
|
|
```ls``` using its equality comparator.
|
|
|
|
(lset-count ls)
|
|
|
|
* ```ls``` - lset instance
|
|
|
|
Returns the number of elements in given lset.
|
|
|
|
(lset-add ls [el ...])
|
|
|
|
* ```ls``` - lset instance
|
|
* ```el``` - element(s) to add
|
|
|
|
Adds given element(s) ```el``` to the lset instance ```ls``` returning
|
|
a new lset instance.
|
|
|
|
(lset-remove ls el)
|
|
|
|
* ```ls``` - lset instance
|
|
* ```el``` - element to remove
|
|
|
|
If given lset instance ```ls``` contains the element ```el```
|
|
provided, it is removed and the new lset is returned. If the element
|
|
is not contained in ```ls```, it is returned intact.
|
|
|
|
(list->lset lst [comparator])
|
|
|
|
* ```lst``` - list to convert
|
|
* ```comparator``` - equality comparison procedure, defaults to ```equal?```
|
|
|
|
Returns a new lset with the comparator provided containing all
|
|
elements in given list.
|
|
|
|
(lset->list ls)
|
|
|
|
* ```ls``` - lset instance
|
|
|
|
Returns the list of elements in given lset.
|
|
|
|
(lset-merge ls1 ls2)
|
|
|
|
* ```ls1``` - lset instance
|
|
* ```ls2``` - lset instance
|
|
|
|
Returns a new lset instance with all elements in both lset instances given.
|
|
|
|
(lset-intersect ls1 ls2)
|
|
|
|
* ```ls1``` - lset instance
|
|
* ```ls2``` - lset instance
|
|
|
|
Returns a new lset instance containing elements present both in
|
|
```ls1``` and ```ls2```.
|
|
|
|
(lset-subtract ls1 ls2)
|
|
|
|
Returns a new lset instance from ```ls1``` with all elements in
|
|
```ls2``` removed from it.
|
|
|
|
(lset=? ls1 ls2)
|
|
|
|
* ```ls1``` - lset instance
|
|
* ```ls2``` - lset instance
|
|
|
|
Returns true if the sets contain exactly the same values.
|