# 22. set_bbbtree: Balanced Binary Trees: Sets

This module implements sets using bounded balanced binary trees. It is adapted from the Mercury version. The original is available from http://www.cs.mu.oz.au/research/mercury/. That implementation is based on `Functional Pearls: Efficient sets -a balancing act' by Stephen Adams, J. Functional Programming 3 (4): 553-561, Oct 1993.

## 22.1. List of Predicates

This section lists the predicates defined by this module.

### 22.1.1. set_bbbtree__init(?Bbbtree)

Bbbtree is initialized as an empty set.

### 22.1.2. set_bbbtree__empty(?Bbbtree)

Succeeds if Bbbtree is the empty set.

### 22.1.3. set_bbbtree__non_empty(?Bbbtree)

Succeeds if Bbbtree is a non-empty set.

### 22.1.4. set_bbbtree__size(+Bbbtree,?Integer)

Integer is the cardinality of the set Bbbtree.

### 22.1.5. set_bbbtree__is_member(+El,+Bbbtree,?Bool)

Bool is the atom yes if El is an element of Bbbtree. Otherwise it is the atom no.

### 22.1.6. set_bbbtree__member(?El,+Bbbtree)

El is an element of Bbbtree. Can be used to enumerate all elements of Bbbtree.

### 22.1.7. set_bbbtree__least(+Bbbtree,?El)

El is the least element occurring in Bbbtree, using the standard ordering of terms.

### 22.1.8. set_bbbtree__largest(+Bbbtree,?El)

El is the largest element occurring in Bbbtree, using the standard ordering of terms.

### 22.1.9. set_bbbtree__singleton_set(?BbbTree,?El)

Bbbtree is a set with single element El.

### 22.1.10. set_bbbtree__equal(+BbbtreeA,+BbbtreeB)

BbbtreeA and BbbtreeB are the same sets.

### 22.1.11. set_bbbtree__insert(+BbbtreeA,+El,-BbbtreeB[,?New])

BbbtreeB is the result of inserting El in BbbtreeA. The optional fourth argument is the atom yes if El is not an element of *BbbtreeA*; otherwise it is the atom no.

### 22.1.12. set_bbbtree__insert_list(+BbbtreeA,+List,-BbbtreeB)

BbbtreeB is the result of inserting each of the elements in List to BbbtreeA.

### 22.1.13. set_bbbtree__delete(+BbbtreeA,+El,-BbbtreeB

BbbtreeB is the result of removing the element El from BbbtreeA. The predicate succeeds if El is not an element of BbbtreeA (cf. set_bbbtree__remove).

### 22.1.14. set_bbbtree__delete_list(+List,+BbbtreeA,-BbbtreeB)

BbbtreeB is the result of deleting each of the elements of List from BbbtreeA. The elements are not required to be contained in BbbtreeA (cf. set_bbbtree__remove_list).

### 22.1.15. set_bbbtree__remove(+BbbtreeA,+El,-BbbtreeB

BbbtreeB is the result of removing the element El from BbbtreeA. The predicate fails if El is not an element of BbbtreeA (cf. set_bbbtree__delete)

### 22.1.16. set_bbbtree__remove_list(+List,+BbbtreeA,-BbbtreeB)

*BbbtreeB is the result of deleting each of the elements of List from BbbtreeA. The elements are required to be contained in BbbtreeA (cf. set_bbbtree__delete_list).

### 22.1.17. set_bbbtree__remove_least(+BbbtreeA,?Least,-BbbtreeB)

BbbtreeB is the result of removing the least element Least from BbbtreeA, in the standard ordering of terms.

### 22.1.18. set_bbbtree__remove_largest(+BbbtreeA,?Largest,-BbbtreeB)

BbbtreeB is the result of removing the largest element Largest from BbbtreeA, in the standard ordering of terms.

### 22.1.19. set_bbbtree__list_to_set(+List,-Bbbtree)

Bbbtree is a set containing precisely all elements of List.

### 22.1.20. set_bbbtree__sorted_list_to_set(+SortedList,?Bbbtree)

Bbbtree is the set containing precisely the elements of SortedList.

### 22.1.21. set_bbbtree__sorted_list_to_set_len(+SortedList,?Bbbtree,+Len)

Bbbtree is the set containing precisely the elements of SortedList. Len is the length of SortedList.

### 22.1.22. set_bbbtree__to_sorted_list(+Bbbtree,?SortedList)

SortedList is a sorted list of the elements of the set Bbbtree.

### 22.1.23. set_bbbtree__union(+BbbtreeA,+BbbtreeB,-BbbtreeC)

BbbtreeC is the union of BbbtreeA and BbbtreeB.

### 22.1.24. set_bbbtree__power_union(+Bbbtrees,-BbbtreeC)

Bbbtrees is a set of sets. BbbtreeC is the union of all of of these sets.

### 22.1.25. set_bbbtree__intersect(+BbbtreeA,+BbbtreeB,-BbbtreeC)

BbbtreeC is the intersection of BbbtreeA and BbbtreeB.

### 22.1.26. set_bbbtree__power_intersect(+Bbbtrees,-BbbtreeC)

Bbbtrees is a set of sets. BbbtreeC is the set containing the elements which occur in each of Bbbtrees

### 22.1.27. set_bbbtree__difference(+BbbtreeA,+BbbtreeB,-BbbtreeC)

BbbtreeC is the set BbbtreeA minus all elements of BbbtreeB.

### 22.1.28. set_bbbtree__subset(+BbbtreeA,+BbbtreeB)

BbbtreeA is a subset of BbbtreeB.

### 22.1.29. set_bbbtree__superset(+BbbtreeA,+BbbtreeB)

BbbtreeA is a superset of BbbtreeB.