8 Generic Function convert

The convert generic function provides convenient conversions between many FSet types. It is called with the first argument to-type being a symbol — normally a quoted constant — that specifies the target type of the conversion, and the second argument being the collection to be converted. (This is the opposite order from cl:coerce.) Many methods have additional keyword parameters to further specify details of the conversion.

When to-type is one of the abstract types – set, bag, map etc. – the only guarantee is that convert will return an instance of the requested type. The choices of implementation and organization are up to FSet, and there’s no option to request a specific organization. In contrast, when to-type is one of the concrete types – wb-set, ch-set, wb-map, etc. – the convert method accepts keyword arguments specifying the organization (e.g. compare-fn-name), and guarantees to return a collection of that type and organization; including the case where no organization is specified, in which convert is guaranteed to return a collection of the default organization (the one using fset:compare).

Method summary:

to-type (symbol)collection typenotes
setset0
ch-setset15
ch-setch-set0, 15
wb-setset0, 15
wb-setwb-set0, 15
setlist2
ch-setlist15
wb-setlist15, 18
setseq2
ch-setseq15
wb-setseq15, 18
setsequence2, 21
ch-setsequence15, 21
wb-setsequence15, 18, 21
listset
vectorset
 
bagbag0
ch-bagbag15
ch-bagch-bag0, 15
wb-bagbag15
wb-bagwb-bag0, 15
bagset2
bagwb-set1
ch-bagset15
ch-bagch-set9, 15
wb-bagset15
wb-bagwb-set9, 15
setwb-bag1
wb-setwb-bag15
setch-bag2
ch-setch-bag15
baglist2, 3, 4
ch-baglist3, 4, 15
wb-baglist3, 4, 15, 18
bagseq2, 3
ch-bagseq3, 15
wb-bagseq3, 15, 18
bagsequence1, 3, 21
ch-bagsequence3, 21
wb-bagsequence3, 15, 18, 21
listbag3
seqbag3
vectorbag3
alistbag
 
mapmap0
ch-mapmap16, 20
wb-mapmap16, 20
ch-mapch-map0, 16, 20
wb-mapwb-map0, 16, 20
maplist2, 6, 7, 18, 19
ch-maplist6, 7, 16, 19
wb-maplist6, 7, 16, 18, 19
mapseq2, 6, 7, 19
ch-mapseq6, 7, 16, 19
wb-mapseq6, 7, 16, 18, 19
mapsequence2, 6, 7, 19, 21
ch-mapsequence6, 7, 16, 19, 21
wb-mapsequence6, 7, 16, 18, 19, 21
mapbag2, 19
ch-mapbag16, 19
wb-mapbag16, 19
maphash-table2, 19
ch-maphash-table16, 19
wb-maphash-table16, 19
setmap2, 5
listmap5
alistmap
seqmap5
vectormap5
hash-tablemap8
 
seqseq0
wb-seqwb-seq0
seqlist1, 9, 23
wb-seqlist9, 23
seqvector1, 9
wb-seqvector9
seqset1
wb-seqset
seqbag1, 3, 5
wb-seqbag3, 5
seqmap1, 5, 19
wb-seqmap5, 19
listwb-seq
vectorwb-seq
stringwb-seq14
base-stringwb-seq14
 
2-relation2-relation0
ch-2-relationch-2-relation0, 16
wb-2-relationwb-2-relation0, 16
2-relationset6, 2
ch-2-relationset6, 16
wb-2-relationset6, 16
setch-2-relation2, 5
setwb-2-relation1, 5
ch-set2-relation5
wb-set2-relation5
2-relationch-map2, 10
ch-2-relationch-map2, 10, 16
2-relationwb-map1, 10
wb-2-relationwb-map10, 16
2-relationlist2, 6
ch-2-relationlist6, 16
wb-2-relationlist6, 16
2-relationseq2, 6
ch-2-relationseq6, 16
wb-2-relationseq6, 16
mapwb-2-relation1, 11, 19
mapch-2-relation2, 11, 19
wb-mapwb-2-relation11, 16, 19
ch-mapch-2-relation11, 16, 19
map-to-setsch-2-relation12
map-to-setswb-2-relation12
list2-relation5
 
tupletuple0
dyn-tupledyn-tuple0
maptuple2
ch-maptuple16
wb-maptuple16
tuplemap13, 17
dyn-tuplemap17
listtuple5
tuplelist6, 7, 13
dyn-tuplelist7
 
replay-setreplay-set0
wb-replay-setreplay-set15
ch-replay-setreplay-set15
wb-replay-setwb-replay-set0, 15
ch-replay-setch-replay-set0, 15
seqreplay-set1, 22
wb-seqreplay-set22
setch-replay-set2, 22
ch-setch-replay-set15, 22
setwb-replay-set1, 22
wb-setwb-replay-set15, 22
replay-setlist2
ch-replay-setlist15
wb-replay-setlist15
replay-setseq2
ch-replay-setseq15
wb-replay-setseq15
replay-setsequence2, 21
ch-replay-setsequence15, 21
wb-replay-setsequence15, 21
listreplay-set
vectorreplay-set
 
replay-mapreplay-map0
wb-replay-mapwb-replay-map0
ch-replay-mapch-replay-map0
mapwb-replay-map1
mapch-replay-map2
wb-mapwb-replay-map
ch-mapch-replay-map
replay-maplist2, 6
wb-replay-maplist6
replay-mapseq2, 6
wb-replay-mapseq6
replay-mapsequence2, 6, 21
wb-replay-mapsequence6, 21
listreplay-map5, 24
vectorreplay-map5, 24
seqreplay-map5, 19, 24
wb-seqreplay-map5, 19, 24
 
listlist0
vectorvector0
listsequence21
vectorsequence21
stringsequence21
base-stringsequence21

Notes:

  1. Identity conversion, provided for convenience. (If the method also accepts an organization, then it performs the identity conversion only if the organization of the argument matches that requested.)
  2. Constructs the WB-tree implementation of its type (wb-set etc.).
  3. Constructs the CHAMP implementation of its type (ch-set etc.).
  4. Has keyword parameter pairs?. If true, treats the input elements as pairs (represented as conses) of a value and a count (multiplicity).
  5. Has keyword parameter from-type. If it’s the symbol alist, treats the input elements as pairs (as conses) of a value and a count. Deprecated; use pairs?.
  6. Has keyword parameter pair-fn, defaulting to #'cons, which specifies the function used to combine each key/value pair.
  7. Has keyword parameters key-fn and value-fn, used to extract a key/value pair from each input element. Defaults are #'car and #'cdr.
  8. If a key occurs more than once in the input, the result will have the value associated with the last occurrence.
  9. All keyword arguments are forwarded to make-hash-table.
  10. Optimized O(n) algorithm.
  11. Has keyword parameter from-type. If it’s the symbol map-to-sets, the range elements must all be sets, and the result pairs each domain element with each element of the corresponding range set. Otherwise, the result pairs each domain element with the corresponding range element directly.
  12. The relation must be a function (must have only one range value per domain value). See Method conflicts (2-relation).
  13. Returns a map mapping each domain value to the set of corresponding range values. The default of the result is the empty set.
  14. Constructs a dyn-tuple.
  15. Always returns a string (or base-string, if specified). Signals a non-char-seq-error if the seq contains a non-character. Signals a type-error if a base-string is specified and it encounters a non-base character.
  16. Has keyword parameter compare-fn-name. If nonnull, must be a symbol, the name of the comparison function to be used. The returned set will be converted, if necessary, to use the specified function, or to use compare if one is not specified.
  17. Has keyword parameters key-compare-fn-name band val-compare-fn-name. If nonnull, these must be symbols, the names of the key and value comparison functions, respectively, to be used. The returned map will be converted, if necessary, to use the specified functions, or to use compare for those not specified.
  18. Has keyword parameter autokey?. if true, then any keys of the map that are not instances of tuple-key are automatically converted to such instances using get-tuple-key.
  19. Has keyword parameter input-sorted?. If true, uses an algorithm optimized for the case where the input is sorted: it runs in O(n) time and is much faster, but is substantially slower than the default algorithm if the input is completely unsorted. “Sorted” here means that the input is in the same order as the collection being built. The algorithm’s correctness doesn’t depend on the sorting, only its performance; so it’s okay if a few elements are out of order.
  20. Has keyword parameter default, which specifies the default of the result; if not supplied, the default is nil. Also has keyword parameter no-default? to specify no default.
  21. Has keyword parameter default, which specifies the default of the result; if not supplied, the default is the same as that of the argument. Also has keyword parameter no-default? to specify no default.
  22. sequence here refers to a CL sequence – either a list or a vector, unless the implementation has more sequence subtypes. FSet’s seq is not a subtype of sequence.
  23. O(1), provided the implementation and organization, if applicable, are unchanged.
  24. Has keyword parameter reverse?, which if true, reverses the order.
  25. Has keyword parameter keys-only?; if true, converts the key sequence to the target type, omitting the values and ignoring pair-fn. If it’s true and to-type is seq or wb-seq, the conversion is O(1).