Next: srfi sets-and-bags compar, Previous: srfi sets-and-bags theory, Up: srfi sets-and-bags [Index]
Return a newly allocated bag containing all the unique elements in all
the bag arguments, such that the count of each unique element in
the result is equal to the sum of the counts of that element in the
arguments. It differs from bag-union
by treating identical
elements as potentially distinct rather than attempting to match them
up.
(import (vicare) (srfi :113) (srfi :114)) (let* ((B1 (bag fixnum-comparator 1 2)) (B2 (bag fixnum-comparator 2 3)) (B3 (bag fixnum-comparator 3 4)) (B (bag-sum B1 B2 B3))) (bag->list B #t)) ⇒ (1 2 2 3 3 4)
Like bag-sum
but it is permitted to mutate and return bag0
rather than allocating a new set.
Return a newly allocated bag containing all the unique elements in bag, where the count of each unique element in the bag is equal to the count of that element in bag multiplied by N.
(import (vicare) (srfi :113) (srfi :114)) (let* ((B1 (bag fixnum-comparator 1 2)) (B (bag-product 0 B1))) (bag->list B #t)) ⇒ () (let* ((B1 (bag fixnum-comparator)) (B (bag-product 2 B1))) (bag->list B #t)) ⇒ () (let* ((B1 (bag fixnum-comparator 1 2)) (B (bag-product 3 B1))) (bag->list B #t)) ⇒ (1 1 1 2 2 2)
Like bag-product
but it is permitted to mutate and return
bag rather than allocating a new set.
Return the number of unique elements of bag.
Return an exact integer representing the number of times that element appears in bag.
Apply proc to each unique element of bag in arbitrary order, passing the element and the number of times it occurs in bag, and discarding the returned values. Return an unspecified result.
Invoke proc on each unique element of bag in arbitrary order, passing the number of occurrences as a second argument and the result of the previous invocation as a third argument. For the first invocation: nil is used as the third argument. Return the result of the last invocation.
(import (vicare) (srfi :113) (srfi :114)) (let ((B (bag fixnum-comparator))) (bag-fold-unique (lambda (elm count knil) (cons (list elm count) knil)) '() B)) ⇒ '() (let ((B (bag fixnum-comparator 1 2 3))) (bag-fold-unique (lambda (elm count knil) (cons (list elm count) knil)) '() B)) ⇒ ((1 1) (2 1) (3 1))
Linear update procedures that return a bag with the same elements as bag, but with the element count of element in bag increased or decreased by the exact integer count (but not less than zero).
Return a newly allocated set containing the unique elements (in the sense of the equality predicate) of bag.
Return a newly allocated bag containing the elements of set.
return a bag containing the elements of both bag and set. In all cases, the comparator of the result is the same as the comparator of the argument or arguments.
Return a newly allocated alist whose keys are the unique elements of bag and whose values are the number of occurrences of each element.
As Vicare extension, if the optional argument compar is present:
#f
: the function behaves as if compar
is not present.
#t
: the resulting alist is sorted using the
standard list-sort
and the comparison procedure from the
set or bag comparator, so that the pairs with lesser cars
come first.
list-sort
and compar as comparison predicate, so that the
pairs with lesser cars come first.
Usage examples:
(import (vicare) (srfi :113) (srfi :114)) (let ((B (bag fixnum-comparator 1 2 3))) (bag->alist B #t)) ⇒ ((1 . 1) (2 . 1) (3 . 1)) (let ((B (bag fixnum-comparator 1 1 2 2 3 3))) (bag->alist B fx<?)) ⇒ ((1 . 2) (2 . 2) (3 . 2))
Return a newly allocated bag based on comparator, where the keys of alist specify the elements and the corresponding values of alist specify how many times they occur.
(import (vicare) (srfi :113) (srfi :114)) (let ((B (alist->bag fixnum-comparator '()))) (bag->alist B)) ⇒ () (let ((B (alist->bag fixnum-comparator '((1 . 1) (2 . 1) (3 . 1))))) (bag->alist B #t)) ⇒ ((1 . 1) (2 . 1) (3 . 1)) (let ((B (alist->bag fixnum-comparator '((1 . 2) (2 . 2) (3 . 2))))) (bag->alist B fx<?)) ⇒ ((1 . 2) (2 . 2) (3 . 2))
Next: srfi sets-and-bags compar, Previous: srfi sets-and-bags theory, Up: srfi sets-and-bags [Index]