source:
libcfa/src/bits/collection.hfa@
ce1d721
| Last change on this file since ce1d721 was ab1b971, checked in by , 5 years ago | |
|---|---|
|
|
| File size: 2.2 KB | |
| Rev | Line | |
|---|---|---|
| [ab1b971] | 1 | // |
| 2 | // Cforall Version 1.0.0 Copyright (C) 2021 University of Waterloo | |
| 3 | // | |
| 4 | // The contents of this file are covered under the licence agreement in the | |
| 5 | // file "LICENCE" distributed with Cforall. | |
| 6 | // | |
| 7 | // bits/collection.hfa -- PUBLIC | |
| 8 | // Intrusive singly-linked list | |
| 9 | // | |
| 10 | // Author : Colby Alexander Parsons & Peter A. Buhr | |
| 11 | // Created On : Thu Jan 21 19:46:50 2021 | |
| 12 | // Last Modified By : | |
| 13 | // Last Modified On : | |
| 14 | // Update Count : | |
| 15 | // | |
| [e43aa14] | 16 | |
| [ab1b971] | 17 | #pragma once |
| [5e82d56] | 18 | |
| 19 | struct Colable { | |
| [ab1b971] | 20 | // next node in the list |
| [5e82d56] | 21 | // invariant: (next != 0) <=> listed() |
| [ab1b971] | 22 | struct Colable * next; |
| [5e82d56] | 23 | }; |
| [e43aa14] | 24 | #ifdef __cforall |
| 25 | static inline { | |
| [7c1144b] | 26 | // PUBLIC |
| 27 | ||
| [5e82d56] | 28 | void ?{}( Colable & co ) with( co ) { |
| 29 | next = 0p; | |
| 30 | } // post: ! listed() | |
| 31 | ||
| 32 | // return true iff *this is an element of a collection | |
| 33 | bool listed( Colable & co ) with( co ) { // pre: this != 0 | |
| [636d3715] | 34 | return next != 0p; |
| [5e82d56] | 35 | } |
| 36 | ||
| [7c1144b] | 37 | Colable & getNext( Colable & co ) with( co ) { |
| 38 | return *next; | |
| [5e82d56] | 39 | } |
| 40 | ||
| [7c1144b] | 41 | // PRIVATE |
| 42 | ||
| [5e82d56] | 43 | Colable *& Next( Colable * cp ) { |
| 44 | return cp->next; | |
| 45 | } | |
| [636d3715] | 46 | |
| [e43aa14] | 47 | // // wrappers to make Collection have T |
| [fd54fef] | 48 | // forall( T & ) { |
| [e43aa14] | 49 | // T *& Next( T * n ) { |
| 50 | // return (T *)Next( (Colable *)n ); | |
| 51 | // } | |
| 52 | // } // distribution | |
| [5e82d56] | 53 | } // distribution |
| 54 | ||
| [481cf3a] | 55 | static inline forall( T & | { T *& Next ( T * ); } ) { |
| [19de7864] | 56 | bool listed( T * n ) { |
| 57 | return Next( n ) != 0p; | |
| 58 | } | |
| 59 | } | |
| [636d3715] | 60 | |
| [5e82d56] | 61 | struct Collection { |
| 62 | void * root; // pointer to root element of list | |
| 63 | }; | |
| 64 | ||
| [e43aa14] | 65 | static inline { |
| [5e82d56] | 66 | // class invariant: root == 0 & empty() | *root in *this |
| 67 | void ?{}( Collection &, const Collection & ) = void; // no copy | |
| 68 | Collection & ?=?( const Collection & ) = void; // no assignment | |
| 69 | ||
| [ab1b971] | 70 | void ?{}( Collection & collection ) with( collection ) { |
| [5e82d56] | 71 | root = 0p; |
| 72 | } // post: empty() | |
| 73 | ||
| 74 | bool empty( Collection & collection ) with( collection ) { // 0 <=> *this contains no elements | |
| 75 | return root == 0p; | |
| 76 | } | |
| [636d3715] | 77 | |
| [5e82d56] | 78 | void * head( Collection & collection ) with( collection ) { |
| 79 | return root; | |
| 80 | } // post: empty() & head() == 0 | !empty() & head() in *this | |
| 81 | } // distribution | |
| 82 | ||
| 83 | ||
| 84 | struct ColIter { | |
| [9536761] | 85 | void * curr; // element returned by | |
| [5e82d56] | 86 | }; |
| 87 | ||
| [e43aa14] | 88 | static inline { |
| [5e82d56] | 89 | void ?{}( ColIter & colIter ) with( colIter ) { |
| 90 | curr = 0p; | |
| 91 | } // post: elts = null | |
| [636d3715] | 92 | |
| [fd54fef] | 93 | forall( T & ) { |
| [636d3715] | 94 | T * Curr( ColIter & ci ) with( ci ) { |
| 95 | return (T *)curr; | |
| 96 | } | |
| 97 | } // distribution | |
| [5e82d56] | 98 | } // distribution |
| [9536761] | 99 | #endif |
Note:
See TracBrowser
for help on using the repository browser.