The Sequence interface

A "Sequence(Elem).T" (or just a {\it sequence}) represents an extensible sequence of "Elem.T"s.

The first group of methods have side effects on the sequence. The call

| s.init(sizeHint)

initializes "s" to be the empty sequence. Furthermore "init" assumes that at least "sizeHint" elements will be added to the sequence; these operations may be executed more efficiently than if "sizeHint" was defaulted. The call

| s.fromArray(a)

initializes "s" to be the sequence with elements "a[0],~...,~a[LAST(a)]". The call

| s.addhi(x)

appends "x" to the end of "s". Thus it does not change the index of any existing element. The call

| s.addlo(x)

appends "x" to the front of "s". Thus it increases the index of all existing elements by one. The call

| s.remhi()

removes and returns the last element of "s". Thus it does not change the index of any of "s"'s other elements. If "s" is empty, "s.remhi()" causes a checked runtime error. The call

| s.remlo()

removes and returns the first element of "s". Thus it decreases the index of all other elements of "s" by one. If "s" is empty, "s.remlo()" causes a checked runtime error. The call

| s.put(i, x)

replaces element "i" of "s" with "x". Element "0" is the first element. It is a checked runtime error unless "i" is less than "s.size()".

The second group of methods have no side effect on the sequence. The call

| s.size()

returns the number of elements in "s". The call

| s.get(i)

returns element "i" of "s". It is a checked runtime error unless "i" is less than "s.size()". The call

| s.gethi()

returns the last element of "s"; that is, it is equivalent to "s.get(s.size()-1)". The call

| s.getlo()

returns the first element of "s"; that is, it is equivalent to "s.get(0)".


garrett@cs.washington.edu