Chapter 6 Wrapped Class Reference

6.7 Data Structures

The wrapped Data Structures (DS) wrapped classes of AM2 provide generic optimized data structures. The user could reimplement these using lists but the implementation would be less efficient. Data structure classes are easy to wrap, and a good place for the novice to begin to augment the set of AM2 wrapped classes. Documentation for the following classes appear in this section:

Note that the Data Structures wrapped classes do not inherit from each other, thus no inheritance diagram is provided here.

6.7.1 DSqueue

This class implements a traditional first-in-first-out (FIFO) queue.

Superclasses

None

Methods

on Enqueue: any value

Adds the value to the end of the queue.

on Dequeue: return any

Returns the first value and removes it from the queue.

on First: return any

Returns the first value but does not remove it from the queue.

on IsEmpty: return boolean

Returns TRUE if the queue is empty.

on Unparse: return string

Returns a human-readable description of all entries.

on Clear

Clears the queue of elements.

Attributes

None

Activities

None

Example

1 on Assert: boolean condition

2 {

3 if (! condition)

4 {

5 die("assertion failed!");

6 }

7 }

8

9 upon Construct

10 {

11 DSqueue q;

12 integer i = 6;

13 string s = "heather";

14 list l = {"this", "is", "a", "list"};

15 {"Assert", "IsEmpty" => q} => theApp;

16 {"Enqueue", 6} => q;

17 {"Assert", !("IsEmpty" => q)} => theApp;

18 {"Enqueue", "heather"} => q;

19 {"Enqueue", {"this", "is", "a", "list"}} => q;

20 {"Assert", i == "First" => q} => theApp;

21 {"Assert", i == "Dequeue" => q} => theApp;

22 {"Assert", s == "Dequeue" => q} => theApp;

23 {"Assert", l == "Dequeue" => q} => theApp;

24 {"Assert", "IsEmpty" => q} => theApp;

25 }

26 on Init

27 {

28 DSqueue q;

29 integer i = 6; string s = "heather";

30 list l = {"this", "is", "a", "list"};

31 "IsEmpty" => q; // TRUE

32 echo("Unparse" => q);

33 {"Enqueue", 6} => q;

34 echo("Unparse" => q);

35 "IsEmpty" => q; // FALSE

36 {"Enqueue", "heather"} => q;

37 echo("Unparse" => q);

38 {"Enqueue", {"this", "is", "a", "list"}} => q;

39 echo("Unparse" => q);

40 i == "First" => q; // TRUE

41 i == "Dequeue" => q; // TRUE

42 s == "Dequeue" => q; // TRUE

43 l == "Dequeue" => q; // TRUE

44 "IsEmpty" => q; // TRUE

45 }

6.7.2 DSstack

This class implements a traditional last-in-first-out (LIFO) stack.

Superclasses

None

Methods

on Push: any value

Adds the value to the top of the stack.

on Pop: return any

Returns the top value and removes it from the stack.

on Top: return any

Returns the top value but does not remove it from the stack.

on IsEmpty: return boolean

Returns TRUE if the stack is empty.

on Unparse: return string

Returns a human-readable description of all entries.

on Clear

Clears the stack of elements.

Attributes

None

Activities

None

Example

1 on Assert: boolean condition

2 {

3 if (! condition)

4 {

5 die("assertion failed!");

6 }

7 }

8

9 upon Construct

10 {

11 DSstack stack;

12 integer i = 6;

13 string s = "heather";

14 list l = {"this", "is", "a", "list"};

15

16 {"Assert", "IsEmpty" => stack} => theApp;

17

18 {"Push", 6} => stack;

19

20 {"Assert", !("IsEmpty" => stack)} => theApp;

21

22 {"Push", "heather"} => stack;

23 {"Push", {"this", "is", "a", "list"}} => stack;

24

25 {"Assert", l == "Top" => stack} => theApp;

26 {"Assert", l == "Pop" => stack} => theApp;

27 {"Assert", s == "Pop" => stack} => theApp;

28 {"Assert", i == "Pop" => stack} => theApp;

29

30 {"Assert", "IsEmpty" => stack} => theApp;

31 }

32

33 on Init

34 {

35 DSstack stack;

36 integer i = 6;

37 string s = "heather";

38 list l = {"this", "is", "a", "list"};

39

40 "IsEmpty" => stack; // TRUE

41 echo("Unparse" => stack);

42

43 {"Push", 6} => stack;

44 echo("Unparse" => stack);

45

46 "IsEmpty" => stack; // FALSE

47

48 {"Push", "heather"} => stack;

49 echo("Unparse" => stack);

50 {"Push", {"this", "is", "a", "list"}} => stack;

51 echo("Unparse" => stack);


6.7.1 - DSqueue
Superclasses
Methods
Attributes
Activities
Example
6.7.2 - DSstack
Superclasses
Methods
Attributes
Activities
Example

AM2 Documentation - 19 NOV 1996

Generated with Harlequin WebMaker