4
* Copyright © 2003 Keith Packard
6
* Permission to use, copy, modify, distribute, and sell this software and its
7
* documentation for any purpose is hereby granted without fee, provided that
8
* the above copyright notice appear in all copies and that both that
9
* copyright notice and this permission notice appear in supporting
10
* documentation, and that the name of Keith Packard not be used in
11
* advertising or publicity pertaining to distribution of the software without
12
* specific, written prior permission. Keith Packard makes no
13
* representations about the suitability of this software for any purpose. It
14
* is provided "as is" without express or implied warranty.
16
* KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
17
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
18
* EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
19
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
20
* DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
21
* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
22
* PERFORMANCE OF THIS SOFTWARE.
26
public bool contains (&poly[*] a, poly v) {
27
for (int i = 0; i < dim(a); i++)
33
public poly append (&poly[*] a, poly v) {
36
a = (poly[dim(a)+1]) { [i] = i < dim(a) ? a[i] : v };
40
public poly push (&poly[*] a, poly v) {
41
a = (poly[dim(a)+1]) { [i] = i < dim(a) ? a[i] : v };
45
public exception empty (&poly[*] a);
47
public poly pop (&poly[*] a) {
51
a = (poly[dim(a)-1]) { [i] = a[i] };
55
public void iterate (&poly[*] a, void (poly v) f) {
56
for (int i = 0; i < dim (a); i++)
60
public void remove (&poly[*] a, poly v) {
61
if (!contains (&a, v))
64
a = (poly[dim(a)-1]) { [i] = found ? a[i+1] :
65
a[i] == v ? (found=true, a[i+1]) : a[i] };