User Tools

Site Tools


at:tutorial:appendix

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revisionBoth sides next revision
at:tutorial:appendix [2008/07/10 14:28] – Added tvcutsemat:tutorial:appendix [2008/07/10 14:31] – * tvcutsem
Line 112: Line 112:
  
 <code> <code>
-// returns the number of elements in the vector (not the capacity of the vector!)+// returns the number of elements in the vector (not its capacity!)
 length() length()
 +
 // returns whether the vector contains elements or not // returns whether the vector contains elements or not
 isEmpty() isEmpty()
 +
 // is the vector at max. capacity? // is the vector at max. capacity?
 atMaxCapacity() atMaxCapacity()
 +
 // return idx'th element or raise an IndexOutOfBounds exception // return idx'th element or raise an IndexOutOfBounds exception
 at(idx) at(idx)
 +
 // write idx'th element or raise IndexOutOfBounds exception // write idx'th element or raise IndexOutOfBounds exception
 //atPut(idx, val) //atPut(idx, val)
 +
 // iterate over the vector // iterate over the vector
 each: iterator, returns nil each: iterator, returns nil
 +
 // map a unary function over the vector, returns a new vector // map a unary function over the vector, returns a new vector
 map: fun map: fun
 +
 // accumulate a function with a given starting value // accumulate a function with a given starting value
 inject: init into: accum; inject: init into: accum;
 +
 // returns a new vector whose elements satisfy "cond" // returns a new vector whose elements satisfy "cond"
 filter: cond; filter: cond;
 +
 // implode a vector of character strings into one text string // implode a vector of character strings into one text string
 implode() implode()
 +
 // join a vector of character strings together with the given string // join a vector of character strings together with the given string
 join(txt) join(txt)
 +
 // returns a range [start,stop[ as a table // returns a range [start,stop[ as a table
 select(start, stop) select(start, stop)
 +
 // appends an element to the back of the vector // appends an element to the back of the vector
 // returns the vector itself // returns the vector itself
 add(element) add(element)
 // alias for add(element) // alias for add(element)
-def <<(element)+<<(element) 
 // insert an element at a given position, causing subsequent elements to shift one pos to the right. Returns this vector // insert an element at a given position, causing subsequent elements to shift one pos to the right. Returns this vector
 insert(atPos, element) insert(atPos, element)
 +
 // delete the element at the given position, shifts all following elements one pos to the left. Returns the value of the element at the deleted position. // delete the element at the given position, shifts all following elements one pos to the left. Returns the value of the element at the deleted position.
 delete(atPos) delete(atPos)
 +
 // adds elements to the back of the vector // adds elements to the back of the vector
 push(element) push(element)
 +
 // deletes elements from the back of the vector // deletes elements from the back of the vector
 pop() pop()
-// return the index of the first element matching the given filter (a unary predicate), or nil if none is found+ 
 +// return the index of the first element matching the unary predicate or nil if none is found
 find: filter find: filter
 +
 // remove the given element from the vector, return true if the element was actually found and deleted, false otherwise // remove the given element from the vector, return true if the element was actually found and deleted, false otherwise
 remove(elt, cmp := defaultComparator) remove(elt, cmp := defaultComparator)
 +
 // remove all objects for which filter(elt) returns true // remove all objects for which filter(elt) returns true
 removeAll: filter removeAll: filter
 +
 // destructively appends otherVector to self. Returns this vector // destructively appends otherVector to self. Returns this vector
 addAll(otherVector) addAll(otherVector)
 +
 // empties the vector // empties the vector
 clear() clear()
 +
 // Return a new vector whose elements form the set-union of all elements in self U otherVector // Return a new vector whose elements form the set-union of all elements in self U otherVector
 union(otherVector, cmp := defaultComparator) union(otherVector, cmp := defaultComparator)
 +
 // Return a new vector whose elements form the set-intersection of all elements in self ^ otherVector // Return a new vector whose elements form the set-intersection of all elements in self ^ otherVector
 intersection(otherVector, cmp := defaultComparator) intersection(otherVector, cmp := defaultComparator)
 +
 // Return a new vector whose elements form the set-difference of self \ otherVector // Return a new vector whose elements form the set-difference of self \ otherVector
 difference(otherVector, cmp := defaultComparator) difference(otherVector, cmp := defaultComparator)
 +
 // Quicksort the vector in-place. The comparator defines the ordering among elements. // Quicksort the vector in-place. The comparator defines the ordering among elements.
 sort(cmp := { |e1,e2| e1 < e2 }) sort(cmp := { |e1,e2| e1 < e2 })
 +
 // Turn the vector into a set without duplicates in O(nlogn + n) // Turn the vector into a set without duplicates in O(nlogn + n)
 // The vector's ordering is lost (it becomes sorted) // The vector's ordering is lost (it becomes sorted)
 uniq(cmp := defaultComparator, ordercmp := {|e1,e2| e1 < e2 }) uniq(cmp := defaultComparator, ordercmp := {|e1,e2| e1 < e2 })
 +
 // return an element drawn randomly using a uniform distribution from the array or raise an EmptyVector exception. // return an element drawn randomly using a uniform distribution from the array or raise an EmptyVector exception.
 random() random()
 +
 // return a table containing all elements of the vector // return a table containing all elements of the vector
 asTable() asTable()
at/tutorial/appendix.txt · Last modified: 2021/09/24 10:28 by elisag