Homepage > Man Pages > Category > Subroutines

Homepage > Man Pages > Name > G# gb_sets

## man page of gb_sets

### gb_sets: General Balanced Trees

Homepage > Man Pages > Name > G

## NAME

gb_sets- General Balanced Trees## DESCRIPTION

An implementation of ordered sets using Prof. Arne Andersson's General Balanced Trees. This can be much more efficient than using ordered lists, for larger sets, but depends on the application.## COMPLEXITY NOTE

The complexity on set operations is bounded by either O(|S|) or O(|T| * log(|S|)), where S is the largest given set, depending on which is fastest for any particular function call. For operating on sets of almost equal size, this implementation is about 3 times slower than using ordered-list sets directly. For sets of very different sizes, however, this solution can be arbitrarily much faster; in practical cases, often between 10 and 100 times. This implementation is particularly suited for accumulating elements a few at a time, building up a large set (more than 100-200 elements), and repeatedly testing for membership in the current set. As with normal tree structures, lookup (membership testing), insertion and deletion have logarithmic complexity.COMPATIBILITY

All of the following functions in this module also exist and do the same thing in thesetsandordsetsmodules. That is, by only changing the module name for each call, you can try out different set representations. *add_element/2.br .br *del_element/2.br .br *filter/2.br .br *fold/3.br .br *from_list/1.br .br *intersection/1.br .br *intersection/2.br .br *is_element/2.br .br *is_set/1.br .br *is_subset/2.br .br *new/0.br .br *size/1.br .br *subtract/2.br .br *to_list/1.br .br *union/1.br .br *union/2.br .br## DATA TYPES

gb_set() = a GB set## EXPORTS

add(Element, Set1) -> Set2 add_element(Element, Set1) -> Set2Types Element = term() Set1 = Set2 = gb_set() Returns a new gb_set formed fromSet1withElementinserted. IfElementis already an element inSet1, nothing is changed.balance(Set1) -> Set2Types Set1 = Set2 = gb_set() Rebalances the tree representation ofSet1. Note that this is rarely necessary, but may be motivated when a large number of elements have been deleted from the tree without further insertions. Rebalancing could then be forced in order to minimise lookup times, since deletion only does not rebalance the tree.delete(Element, Set1) -> Set2Types Element = term() Set1 = Set2 = gb_set() Returns a new gb_set formed fromSet1withElementremoved. Assumes thatElementis present inSet1.delete_any(Element, Set1) -> Set2 del_element(Element, Set1) -> Set2Types Element = term() Set1 = Set2 = gb_set() Returns a new gb_set formed fromSet1withElementremoved. IfElementis not an element inSet1, nothing is changed.difference(Set1, Set2) -> Set3 subtract(Set1, Set2) -> Set3Types Set1 = Set2 = Set3 = gb_set() Returns only the elements ofSet1which are not also elements ofSet2.empty() -> Set new() -> SetTypes Set = gb_set() Returns a new empty gb_set.filter(Pred, Set1) -> Set2Types Pred = fun (E) -> bool() E = term() Set1 = Set2 = gb_set() Filters elements inSet1using predicate functionPred.fold(Function, Acc0, Set) -> Acc1Types Function = fun (E, AccIn) -> AccOut Acc0 = Acc1 = AccIn = AccOut = term() E = term() Set = gb_set() FoldsFunctionover every element inSetreturning the final value of the accumulator.from_list(List) -> SetTypes List = [term()] Set = gb_set() Returns a gb_set of the elements inList, whereListmay be unordered and contain duplicates.from_ordset(List) -> SetTypes List = [term()] Set = gb_set() Turns an ordered-set listListinto a gb_set. The list must not contain duplicates.insert(Element, Set1) -> Set2Types Element = term() Set1 = Set2 = gb_set() Returns a new gb_set formed fromSet1withElementinserted. Assumes thatElementis not present inSet1.intersection(Set1, Set2) -> Set3Types Set1 = Set2 = Set3 = gb_set() Returns the intersection ofSet1andSet2.intersection(SetList) -> SetTypes SetList = [gb_set()] Set = gb_set() Returns the intersection of the non-empty list of gb_sets.is_disjoint(Set1, Set2) -> bool()Types Set1 = Set2 = gb_set() ReturnstrueifSet1andSet2are disjoint (have no elements in common), andfalseotherwise.is_empty(Set) -> bool()Types Set = gb_set() ReturnstrueifSetis an empty set, andfalseotherwise.is_member(Element, Set) -> bool() is_element(Element, Set) -> bool()Types Element = term() Set = gb_set() ReturnstrueifElementis an element ofSet, otherwisefalse.is_set(Term) -> bool()Types Term = term() ReturnstrueifSetappears to be a gb_set, otherwisefalse.is_subset(Set1, Set2) -> bool()Types Set1 = Set2 = gb_set() Returnstruewhen every element ofSet1is also a member ofSet2, otherwisefalse.iterator(Set) -> IterTypes Set = gb_set() Iter = term() Returns an iterator that can be used for traversing the entries ofSet; seenext/1. The implementation of this is very efficient; traversing the whole set usingnext/1is only slightly slower than getting the list of all elements usingto_list/1and traversing that. The main advantage of the iterator approach is that it does not require the complete list of all elements to be built in memory at one time.largest(Set) -> term()Types Set = gb_set() Returns the largest element inSet. Assumes thatSetis nonempty.next(Iter1) -> {Element, Iter2} | noneTypes Iter1 = Iter2 = Element = term() Returns{Element, Iter2}whereElementis the smallest element referred to by the iteratorIter1, andIter2is the new iterator to be used for traversing the remaining elements, or the atomnoneif no elements remain.singleton(Element) -> gb_set()Types Element = term() Returns a gb_set containing only the elementElement.size(Set) -> int()Types Set = gb_set() Returns the number of elements inSet.smallest(Set) -> term()Types Set = gb_set() Returns the smallest element inSet. Assumes thatSetis nonempty.take_largest(Set1) -> {Element, Set2}Types Set1 = Set2 = gb_set() Element = term() Returns{Element, Set2}, whereElementis the largest element inSet1, andSet2is this set withElementdeleted. Assumes thatSet1is nonempty.take_smallest(Set1) -> {Element, Set2}Types Set1 = Set2 = gb_set() Element = term() Returns{Element, Set2}, whereElementis the smallest element inSet1, andSet2is this set withElementdeleted. Assumes thatSet1is nonempty.to_list(Set) -> ListTypes Set = gb_set() List = [term()] Returns the elements ofSetas a list.union(Set1, Set2) -> Set3Types Set1 = Set2 = Set3 = gb_set() Returns the merged (union) gb_set ofSet1andSet2.union(SetList) -> SetTypes SetList = [gb_set()] Set = gb_set() Returns the merged (union) gb_set of the list of gb_sets.## SEE ALSO

gb_trees(3erl), ordsets(3erl), sets(3erl) GB_SETS(3)

Copyright © 2011–2018 by topics-of-interest.com . All rights reserved. Hosted by all-inkl.

Contact · Imprint · Privacy

Page generated in 39.41ms.

elternfragen.net | tier-bedarf.com | daelim-forum.spreadshirt.de