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
RevLine 
[5e82d56]1#pragma once
[e43aa14]2#include <stdio.h> // REMOVE THIS AFTER DEBUGGING
3
[5e82d56]4
5struct Colable {
[e43aa14]6 struct Colable * next; // next node in the list
[5e82d56]7 // invariant: (next != 0) <=> listed()
8};
[e43aa14]9#ifdef __cforall
10static inline {
[7c1144b]11 // PUBLIC
12
[5e82d56]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
[636d3715]19 return next != 0p;
[5e82d56]20 }
21
[7c1144b]22 Colable & getNext( Colable & co ) with( co ) {
23 return *next;
[5e82d56]24 }
25
[7c1144b]26 // PRIVATE
27
[5e82d56]28 Colable *& Next( Colable * cp ) {
29 return cp->next;
30 }
[636d3715]31
[e43aa14]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
[5e82d56]42} // distribution
43
[636d3715]44
[5e82d56]45struct Collection {
46 void * root; // pointer to root element of list
47};
48
[e43aa14]49static inline {
[5e82d56]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 }
[636d3715]61
[5e82d56]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
[e43aa14]72static inline {
[5e82d56]73 void ?{}( ColIter & colIter ) with( colIter ) {
74 curr = 0p;
75 } // post: elts = null
[636d3715]76
77 forall( dtype T ) {
78 T * Curr( ColIter & ci ) with( ci ) {
79 return (T *)curr;
80 }
81 } // distribution
[5e82d56]82} // distribution
[e43aa14]83#endif
Note: See TracBrowser for help on using the repository browser.