Changeset 0cf5b79 for src/libcfa/bits/containers.h
- Timestamp:
- Nov 20, 2017, 12:12:34 PM (7 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- fdd3786
- Parents:
- b7f8cb4
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/libcfa/bits/containers.h
rb7f8cb4 r0cf5b79 15 15 #pragma once 16 16 17 #include <stddef.h> 17 #include "bits/defs.h" 18 #include "libhdr.h" 18 19 19 #include "libhdr.h" 20 //----------------------------------------------------------------------------- 21 // Array 22 //----------------------------------------------------------------------------- 23 24 #ifdef __cforall 25 forall(dtype T) 26 #else 27 #define T void 28 #endif 29 struct __small_array { 30 T * data; 31 __lock_size_t size; 32 }; 33 #undef T 34 35 #ifdef __cforall 36 #define __small_array_t(T) __small_array(T) 37 #else 38 #define __small_array_t(T) struct __small_array 39 #endif 40 41 #ifdef __cforall 42 // 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 #endif 20 65 21 66 //----------------------------------------------------------------------------- … … 23 68 //----------------------------------------------------------------------------- 24 69 25 #ifdef __ CFORALL__70 #ifdef __cforall 26 71 trait is_node(dtype T) { 27 72 T*& get_next( T& ); … … 32 77 // Stack 33 78 //----------------------------------------------------------------------------- 34 #ifdef __ CFORALL__79 #ifdef __cforall 35 80 forall(dtype TYPE | is_node(TYPE)) 36 81 #define T TYPE … … 41 86 T * top; 42 87 }; 88 #undef T 43 89 44 #ifdef __ CFORALL__90 #ifdef __cforall 45 91 #define __stack_t(T) __stack(T) 46 92 #else … … 48 94 #endif 49 95 50 #ifdef __ CFORALL__96 #ifdef __cforall 51 97 forall(dtype T | is_node(T)) 52 void ?{}( __stack(T) & this ) {53 this.top = NULL;98 static inline void ?{}( __stack(T) & this ) { 99 (this.top){ NULL }; 54 100 } 55 101 56 102 forall(dtype T | is_node(T) | sized(T)) 57 void push( __stack(T) & this, T * val ) {103 static inline void push( __stack(T) & this, T * val ) { 58 104 verify( !get_next( *val ) ); 59 105 get_next( *val ) = this.top; … … 62 108 63 109 forall(dtype T | is_node(T) | sized(T)) 64 T * pop( __stack(T) & this ) {110 static inline T * pop( __stack(T) & this ) { 65 111 T * top = this.top; 66 112 if( top ) { … … 75 121 // Queue 76 122 //----------------------------------------------------------------------------- 77 #ifdef __ CFORALL__78 forall(dtype T | is_node(T))123 #ifdef __cforall 124 forall(dtype TYPE | is_node(TYPE)) 79 125 #define T TYPE 80 126 #else … … 85 131 T ** tail; 86 132 }; 133 #undef T 87 134 88 #ifdef __CFORALL__ 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 89 142 forall(dtype T | is_node(T)) 90 void ?{}( __queue(T) & this ) {91 this.head = NULL;92 this.tail = &this.head;143 static inline void ?{}( __queue(T) & this ) { 144 (this.head){ NULL }; 145 (this.tail){ &this.head }; 93 146 } 94 147 95 148 forall(dtype T | is_node(T) | sized(T)) 96 void append( __queue(T) & this, T * val ) {149 static inline void append( __queue(T) & this, T * val ) { 97 150 verify(this.tail != NULL); 98 151 *this.tail = val; … … 101 154 102 155 forall(dtype T | is_node(T) | sized(T)) 103 T * pop_head( __queue(T) & this ) {156 static inline T * pop_head( __queue(T) & this ) { 104 157 T * head = this.head; 105 158 if( head ) { … … 114 167 115 168 forall(dtype T | is_node(T) | sized(T)) 116 T * remove( __queue(T) & this, T ** it ) {169 static inline T * remove( __queue(T) & this, T ** it ) { 117 170 T * val = *it; 118 171 verify( val );
Note: See TracChangeset
for help on using the changeset viewer.