Changes in src/libcfa/bits/containers.h [0cf5b79:ea7d2b0]
- File:
-
- 1 edited
-
src/libcfa/bits/containers.h (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/libcfa/bits/containers.h
r0cf5b79 rea7d2b0 15 15 #pragma once 16 16 17 #include "bits/defs.h" 17 #include <stddef.h> 18 18 19 #include "libhdr.h" 19 20 //-----------------------------------------------------------------------------21 // Array22 //-----------------------------------------------------------------------------23 24 #ifdef __cforall25 forall(dtype T)26 #else27 #define T void28 #endif29 struct __small_array {30 T * data;31 __lock_size_t size;32 };33 #undef T34 35 #ifdef __cforall36 #define __small_array_t(T) __small_array(T)37 #else38 #define __small_array_t(T) struct __small_array39 #endif40 41 #ifdef __cforall42 // forall(otype T | sized(T))43 // static inline void ?{}(__small_array(T) & this) {}44 45 forall(dtype T | sized(T))46 static inline T& ?[?]( __small_array(T) & this, __lock_size_t idx) {47 return ((typeof(this.data))this.data)[idx];48 }49 50 forall(dtype T | sized(T))51 static inline T& ?[?]( const __small_array(T) & this, __lock_size_t idx) {52 return ((typeof(this.data))this.data)[idx];53 }54 55 forall(dtype T | sized(T))56 static inline T* begin( const __small_array(T) & this ) {57 return ((typeof(this.data))this.data);58 }59 60 forall(dtype T | sized(T))61 static inline T* end( const __small_array(T) & this ) {62 return ((typeof(this.data))this.data) + this.size;63 }64 #endif65 20 66 21 //----------------------------------------------------------------------------- … … 68 23 //----------------------------------------------------------------------------- 69 24 70 #ifdef __ cforall25 #ifdef __CFORALL__ 71 26 trait is_node(dtype T) { 72 27 T*& get_next( T& ); … … 77 32 // Stack 78 33 //----------------------------------------------------------------------------- 79 #ifdef __ cforall34 #ifdef __CFORALL__ 80 35 forall(dtype TYPE | is_node(TYPE)) 81 36 #define T TYPE … … 86 41 T * top; 87 42 }; 88 #undef T89 43 90 #ifdef __ cforall44 #ifdef __CFORALL__ 91 45 #define __stack_t(T) __stack(T) 92 46 #else … … 94 48 #endif 95 49 96 #ifdef __ cforall50 #ifdef __CFORALL__ 97 51 forall(dtype T | is_node(T)) 98 static inlinevoid ?{}( __stack(T) & this ) {99 (this.top){ NULL };52 void ?{}( __stack(T) & this ) { 53 this.top = NULL; 100 54 } 101 55 102 56 forall(dtype T | is_node(T) | sized(T)) 103 static inlinevoid push( __stack(T) & this, T * val ) {57 void push( __stack(T) & this, T * val ) { 104 58 verify( !get_next( *val ) ); 105 59 get_next( *val ) = this.top; … … 108 62 109 63 forall(dtype T | is_node(T) | sized(T)) 110 static inlineT * pop( __stack(T) & this ) {64 T * pop( __stack(T) & this ) { 111 65 T * top = this.top; 112 66 if( top ) { … … 121 75 // Queue 122 76 //----------------------------------------------------------------------------- 123 #ifdef __ cforall124 forall(dtype T YPE | is_node(TYPE))77 #ifdef __CFORALL__ 78 forall(dtype T | is_node(T)) 125 79 #define T TYPE 126 80 #else … … 131 85 T ** tail; 132 86 }; 133 #undef T134 87 135 #ifdef __cforall 136 #define __queue_t(T) __queue(T) 137 #else 138 #define __queue_t(T) struct __queue 139 #endif 140 141 #ifdef __cforall 88 #ifdef __CFORALL__ 142 89 forall(dtype T | is_node(T)) 143 static inlinevoid ?{}( __queue(T) & this ) {144 (this.head){ NULL };145 (this.tail){ &this.head };90 void ?{}( __queue(T) & this ) { 91 this.head = NULL; 92 this.tail = &this.head; 146 93 } 147 94 148 95 forall(dtype T | is_node(T) | sized(T)) 149 static inlinevoid append( __queue(T) & this, T * val ) {96 void append( __queue(T) & this, T * val ) { 150 97 verify(this.tail != NULL); 151 98 *this.tail = val; … … 154 101 155 102 forall(dtype T | is_node(T) | sized(T)) 156 static inlineT * pop_head( __queue(T) & this ) {103 T * pop_head( __queue(T) & this ) { 157 104 T * head = this.head; 158 105 if( head ) { … … 167 114 168 115 forall(dtype T | is_node(T) | sized(T)) 169 static inlineT * remove( __queue(T) & this, T ** it ) {116 T * remove( __queue(T) & this, T ** it ) { 170 117 T * val = *it; 171 118 verify( val );
Note:
See TracChangeset
for help on using the changeset viewer.