source: libcfa/src/bits/collection.hfa@ 28c35e2

ADT arm-eh ast-experimental enum forall-pointer-decay jacob/cs343-translation new-ast-unique-expr pthread-emulation qualifiedEnum
Last change on this file since 28c35e2 was accc5dbb, checked in by Colby Alexander Parsons <caparsons@…>, 5 years ago

updated other collections to match changes to sequence.hfa

  • Property mode set to 100644
File size: 1.8 KB
Line 
1#pragma once
2#include <stdio.h> // REMOVE THIS AFTER DEBUGGING
3
4
5struct Colable {
6 struct Colable * next; // next node in the list
7 // invariant: (next != 0) <=> listed()
8};
9#ifdef __cforall
10static inline {
11 // PUBLIC
12
13 void ?{}( Colable & co ) with( co ) {
14 next = 0p;
15 } // post: ! listed()
16
17 // return true iff *this is an element of a collection
18 bool listed( Colable & co ) with( co ) { // pre: this != 0
19 return next != 0p;
20 }
21
22 Colable & getNext( Colable & co ) with( co ) {
23 return *next;
24 }
25
26 // PRIVATE
27
28 Colable *& Next( Colable * cp ) {
29 return cp->next;
30 }
31
32 // // wrappers to make Collection have T
33 // forall( dtype T ) {
34 // T *& Next( T * n ) {
35 // return (T *)Next( (Colable *)n );
36 // }
37
38 // bool listed( T * n ) {
39 // return Next( (Colable *)n ) != 0p;
40 // }
41 // } // distribution
42} // distribution
43
44
45struct Collection {
46 void * root; // pointer to root element of list
47};
48
49static inline {
50 // class invariant: root == 0 & empty() | *root in *this
51 void ?{}( Collection &, const Collection & ) = void; // no copy
52 Collection & ?=?( const Collection & ) = void; // no assignment
53
54 void ?{}( Collection & collection ) with( collection ) {
55 root = 0p;
56 } // post: empty()
57
58 bool empty( Collection & collection ) with( collection ) { // 0 <=> *this contains no elements
59 return root == 0p;
60 }
61
62 void * head( Collection & collection ) with( collection ) {
63 return root;
64 } // post: empty() & head() == 0 | !empty() & head() in *this
65} // distribution
66
67
68struct ColIter {
69 void * curr; // element to be returned by >>
70};
71
72static inline {
73 void ?{}( ColIter & colIter ) with( colIter ) {
74 curr = 0p;
75 } // post: elts = null
76
77 forall( dtype T ) {
78 T * Curr( ColIter & ci ) with( ci ) {
79 return (T *)curr;
80 }
81 } // distribution
82} // distribution
83#endif
Note: See TracBrowser for help on using the repository browser.