LinearAggregate S¶
aggcat.spad line 1698 [edit on github]
S: Type
A linear aggregate is an aggregate whose elements are indexed by integers. Examples of linear aggregates are strings, lists, and arrays. Most of the exported operations for linear aggregates are non-destructive but are not always efficient for a particular aggregate. For example, concat of two lists needs only to copy its first argument, whereas concat of two arrays needs to copy both arguments. Most of the operations exported here apply to infinite objects (e.g. streams) as well to finite ones. If the aggregate is a finite aggregate then it has several additional exports such as reverse, sort, and so on.
- #: % -> NonNegativeInteger if % has finiteAggregate
from Aggregate
- <=: (%, %) -> Boolean if S has OrderedSet and % has finiteAggregate
from PartialOrder
- <: (%, %) -> Boolean if S has OrderedSet and % has finiteAggregate
from PartialOrder
- =: (%, %) -> Boolean if S has BasicType and % has finiteAggregate or S has Hashable and % has finiteAggregate or S has SetCategory
from BasicType
- >=: (%, %) -> Boolean if S has OrderedSet and % has finiteAggregate
from PartialOrder
- >: (%, %) -> Boolean if S has OrderedSet and % has finiteAggregate
from PartialOrder
- ~=: (%, %) -> Boolean if S has BasicType and % has finiteAggregate or S has Hashable and % has finiteAggregate or S has SetCategory
from BasicType
- any?: (S -> Boolean, %) -> Boolean if % has finiteAggregate
from HomogeneousAggregate S
- coerce: % -> OutputForm if S has CoercibleTo OutputForm
from CoercibleTo OutputForm
- concat: (%, %) -> %
concat(u, v)
returns an aggregate consisting of the elements ofu
followed by the elements ofv
. Note: ifw = concat(u, v)
thenw.i = u.i for i in indices u
andw.(j + maxIndex u) = v.j for j in indices v
.
- concat: (%, S) -> %
concat(u, x)
returns aggregateu
with additional elementx
at the end. Note: for lists,concat(u, x) = concat(u, [x])
.
- concat: (S, %) -> %
concat(x, u)
returns aggregateu
with additional elementx
at the front. Note: for lists:concat(x, u) = concat([x], u)
.
- concat: List % -> %
concat(u)
, whereu
is a list of aggregates[a, b, ..., c]
, returns a single aggregate consisting of the elements ofa
followed by those ofb
followed … by the elements ofc
. Note:concat([a, b, ..., c]) = concat(a, concat([b, ..., c]))
.
- construct: List S -> %
from Collection S
- convert: % -> InputForm if S has ConvertibleTo InputForm
from ConvertibleTo InputForm
- copyInto!: (%, %, Integer) -> % if % has finiteAggregate and % has shallowlyMutable
copyInto!(u, v, i)
returns aggregateu
containing a copy ofv
inserted at elementi
.
- count: (S -> Boolean, %) -> NonNegativeInteger if % has finiteAggregate
from HomogeneousAggregate S
- count: (S, %) -> NonNegativeInteger if S has BasicType and % has finiteAggregate
from HomogeneousAggregate S
- delete: (%, Integer) -> %
delete(u, i)
returns a copy ofu
with thei
th element deleted. Note:delete(u, i) = concat(u(minIndex(u)..i - 1), u(i + 1..))
.
- delete: (%, UniversalSegment Integer) -> %
delete(u, i..j)
returns a copy ofu
with thei
th throughj
th element deleted. Note:delete(u, i..j) = concat(u(minIndex(u)..i-1), u(j+1..))
.
- elt: (%, Integer) -> S
- elt: (%, Integer, S) -> S
from EltableAggregate(Integer, S)
- elt: (%, UniversalSegment Integer) -> %
from Eltable(UniversalSegment Integer, %)
- entries: % -> List S
from IndexedAggregate(Integer, S)
- entry?: (S, %) -> Boolean if S has BasicType and % has finiteAggregate
from IndexedAggregate(Integer, S)
- eval: (%, Equation S) -> % if S has Evalable S and S has SetCategory
from Evalable S
- eval: (%, List Equation S) -> % if S has Evalable S and S has SetCategory
from Evalable S
- eval: (%, List S, List S) -> % if S has Evalable S and S has SetCategory
from InnerEvalable(S, S)
- eval: (%, S, S) -> % if S has Evalable S and S has SetCategory
from InnerEvalable(S, S)
- every?: (S -> Boolean, %) -> Boolean if % has finiteAggregate
from HomogeneousAggregate S
- fill!: (%, S) -> % if % has shallowlyMutable
from IndexedAggregate(Integer, S)
- find: (S -> Boolean, %) -> Union(S, failed)
from Collection S
- first: % -> S
from IndexedAggregate(Integer, S)
- first: (%, NonNegativeInteger) -> %
first(u, n)
returns a copy of the firstn
elements ofu
. Error: ifu
has less thann
elements.
- hash: % -> SingleInteger if S has Hashable and % has finiteAggregate
from Hashable
- hashUpdate!: (HashState, %) -> HashState if S has Hashable and % has finiteAggregate
from Hashable
- index?: (Integer, %) -> Boolean
from IndexedAggregate(Integer, S)
- indices: % -> List Integer
from IndexedAggregate(Integer, S)
- insert: (%, %, Integer) -> %
insert(v, u, i)
returns a copy ofu
havingv
inserted beginning at thei
th element. Note:insert(v, u, i) = concat(u(minIndex(u)..i-1), concat(v, u(i..)))
.
- insert: (S, %, Integer) -> %
insert(x, u, i)
returns a copy ofu
havingx
as itsi
th element. Note:insert(x, u, i) = concat(u(minIndex(u)..i-1), concat(x, u(i..)))
.
- latex: % -> String if S has SetCategory
from SetCategory
- leftTrim: (%, S) -> % if S has BasicType and % has finiteAggregate
leftTrim(u, x)
returns a copy ofu
with all leadingx
deleted. For example,leftTrim(" abc ", char " ")
returns"abc "
.
- less?: (%, NonNegativeInteger) -> Boolean
from Aggregate
- map!: (S -> S, %) -> % if % has shallowlyMutable
from HomogeneousAggregate S
- map: ((S, S) -> S, %, %) -> %
map(f, u, v)
returns a new aggregatew
with elementsz = f(x, y)
for corresponding elementsx
andy
fromu
andv
. Note:w.i = f(u.i, v.i)
.- map: (S -> S, %) -> %
from HomogeneousAggregate S
- max: % -> S if S has OrderedSet and % has finiteAggregate
from HomogeneousAggregate S
- max: (%, %) -> % if S has OrderedSet and % has finiteAggregate
from OrderedSet
- max: ((S, S) -> Boolean, %) -> S if % has finiteAggregate
from HomogeneousAggregate S
- maxIndex: % -> Integer
from IndexedAggregate(Integer, S)
- member?: (S, %) -> Boolean if S has BasicType and % has finiteAggregate
from HomogeneousAggregate S
- members: % -> List S if % has finiteAggregate
from HomogeneousAggregate S
- merge: (%, %) -> % if S has OrderedSet and % has finiteAggregate
merge(u, v)
mergesu
andv
in ascending order. Note:merge(u, v) = merge(<=, u, v)
.
- merge: ((S, S) -> Boolean, %, %) -> % if % has finiteAggregate
merge(p, a, b)
returns an aggregatec
which mergesa
andb
. The result is produced by examining each elementx
ofa
andy
ofb
successively. Ifp(x, y)
istrue
, thenx
is inserted into the result; otherwisey
is inserted. Ifx
is chosen, the next element ofa
is examined, and so on. When all the elements of one aggregate are examined, the remaining elements of the other are appended. For example,merge(<, [1, 3], [2, 7, 5])
returns[1, 2, 3, 7, 5]
.
- min: % -> S if S has OrderedSet and % has finiteAggregate
from HomogeneousAggregate S
- min: (%, %) -> % if S has OrderedSet and % has finiteAggregate
from OrderedSet
- minIndex: % -> Integer
from IndexedAggregate(Integer, S)
- more?: (%, NonNegativeInteger) -> Boolean
from Aggregate
- new: (NonNegativeInteger, S) -> %
new(n, x)
returns a new aggregate of sizen
all of whose entries arex
.
- parts: % -> List S if % has finiteAggregate
from HomogeneousAggregate S
- position: (S -> Boolean, %) -> Integer if % has finiteAggregate
position(p, a)
returns the indexi
of the firstx
ina
such thatp(x)
istrue
, andminIndex(a) - 1
if there is no suchx
.
- position: (S, %) -> Integer if S has BasicType and % has finiteAggregate
position(x, a)
returns the indexi
of the first occurrence ofx
in a, andminIndex(a) - 1
if there is no suchx
.
- position: (S, %, Integer) -> Integer if S has BasicType and % has finiteAggregate
position(x, a, n)
returns the indexi
of the first occurrence ofx
ina
wherei >= n
, andminIndex(a) - 1
if no suchx
is found.
- qelt: (%, Integer) -> S
from EltableAggregate(Integer, S)
- qsetelt!: (%, Integer, S) -> S if % has shallowlyMutable
from EltableAggregate(Integer, S)
- reduce: ((S, S) -> S, %) -> S if % has finiteAggregate
from Collection S
- reduce: ((S, S) -> S, %, S) -> S if % has finiteAggregate
from Collection S
- reduce: ((S, S) -> S, %, S, S) -> S if S has BasicType and % has finiteAggregate
from Collection S
- remove: (S -> Boolean, %) -> % if % has finiteAggregate
from Collection S
- remove: (S, %) -> % if S has BasicType and % has finiteAggregate
from Collection S
- removeDuplicates: % -> % if S has BasicType and % has finiteAggregate
from Collection S
- reverse!: % -> % if % has finiteAggregate and % has shallowlyMutable
reverse!(u)
returnsu
with its elements in reverse order.
- reverse: % -> % if % has finiteAggregate
reverse(a)
returns a copy ofa
with elements in reverse order.
- rightTrim: (%, S) -> % if S has BasicType and % has finiteAggregate
rightTrim(u, x)
returns a copy ofu
with all trailing occurrences ofx
deleted. For example,rightTrim(" abc ", char " ")
returns" abc"
.
- select: (S -> Boolean, %) -> % if % has finiteAggregate
from Collection S
- setelt!: (%, Integer, S) -> S if % has shallowlyMutable
from EltableAggregate(Integer, S)
- setelt!: (%, UniversalSegment Integer, S) -> S if % has shallowlyMutable
setelt!(u, i..j, x)
(also written:u(i..j) := x
) destructively replaces each element in the segmentu(i..j)
byx
. The valuex
is returned. Note:u
is destructively changed so thatu.k := x for k in i..j
; its length remains unchanged.
- size?: (%, NonNegativeInteger) -> Boolean
from Aggregate
- smaller?: (%, %) -> Boolean if S has OrderedSet and % has finiteAggregate or % has finiteAggregate and S has Comparable
from Comparable
- sort!: % -> % if S has OrderedSet and % has finiteAggregate and % has shallowlyMutable
sort!(u)
returnsu
with its elements in ascending order.
- sort!: ((S, S) -> Boolean, %) -> % if % has finiteAggregate and % has shallowlyMutable
sort!(p, u)
returnsu
with its elements ordered byp
.
- sort: % -> % if S has OrderedSet and % has finiteAggregate
sort(u)
returns anu
with elements in ascending order. Note:sort(u) = sort(<, u)
.
- sort: ((S, S) -> Boolean, %) -> % if % has finiteAggregate
sort(p, a)
returns a copy ofa
sorted using total ordering predicatep
.
- sorted?: % -> Boolean if S has OrderedSet and % has finiteAggregate
sorted?(u)
tests if the elements ofu
are in ascending order.
- sorted?: ((S, S) -> Boolean, %) -> Boolean if % has finiteAggregate
sorted?(p, a)
tests ifa
is sorted according to predicatep
.
- swap!: (%, Integer, Integer) -> Void if % has shallowlyMutable
from IndexedAggregate(Integer, S)
- trim: (%, S) -> % if S has BasicType and % has finiteAggregate
trim(u, x)
returns a copy ofu
with all occurrences ofx
deleted from right and left ends. For example,trim(" abc ", char " ")
returns"abc"
.
BasicType if S has SetCategory or S has Hashable and % has finiteAggregate or S has BasicType and % has finiteAggregate
CoercibleTo OutputForm if S has CoercibleTo OutputForm
Comparable if S has OrderedSet and % has finiteAggregate or % has finiteAggregate and S has Comparable
ConvertibleTo InputForm if S has ConvertibleTo InputForm
Eltable(UniversalSegment Integer, %)
Evalable S if S has Evalable S and S has SetCategory
Hashable if S has Hashable and % has finiteAggregate
InnerEvalable(S, S) if S has Evalable S and S has SetCategory
OrderedSet if S has OrderedSet and % has finiteAggregate
PartialOrder if S has OrderedSet and % has finiteAggregate
SetCategory if S has SetCategory