Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/libcfa/bits/containers.h

    r0cf5b79 rea7d2b0  
    1515#pragma once
    1616
    17 #include "bits/defs.h"
     17#include <stddef.h>
     18
    1819#include "libhdr.h"
    19 
    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
    6520
    6621//-----------------------------------------------------------------------------
     
    6823//-----------------------------------------------------------------------------
    6924
    70 #ifdef __cforall
     25#ifdef __CFORALL__
    7126        trait is_node(dtype T) {
    7227                T*& get_next( T& );
     
    7732// Stack
    7833//-----------------------------------------------------------------------------
    79 #ifdef __cforall
     34#ifdef __CFORALL__
    8035        forall(dtype TYPE | is_node(TYPE))
    8136        #define T TYPE
     
    8641        T * top;
    8742};
    88 #undef T
    8943
    90 #ifdef __cforall
     44#ifdef __CFORALL__
    9145#define __stack_t(T) __stack(T)
    9246#else
     
    9448#endif
    9549
    96 #ifdef __cforall
     50#ifdef __CFORALL__
    9751        forall(dtype T | is_node(T))
    98         static inline void ?{}( __stack(T) & this ) {
    99                 (this.top){ NULL };
     52        void ?{}( __stack(T) & this ) {
     53                this.top = NULL;
    10054        }
    10155
    10256        forall(dtype T | is_node(T) | sized(T))
    103         static inline void push( __stack(T) & this, T * val ) {
     57        void push( __stack(T) & this, T * val ) {
    10458                verify( !get_next( *val ) );
    10559                get_next( *val ) = this.top;
     
    10862
    10963        forall(dtype T | is_node(T) | sized(T))
    110         static inline T * pop( __stack(T) & this ) {
     64        T * pop( __stack(T) & this ) {
    11165                T * top = this.top;
    11266                if( top ) {
     
    12175// Queue
    12276//-----------------------------------------------------------------------------
    123 #ifdef __cforall
    124         forall(dtype TYPE | is_node(TYPE))
     77#ifdef __CFORALL__
     78        forall(dtype T | is_node(T))
    12579        #define T TYPE
    12680#else
     
    13185        T ** tail;
    13286};
    133 #undef T
    13487
    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__
    14289        forall(dtype T | is_node(T))
    143         static inline void ?{}( __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;
    14693        }
    14794
    14895        forall(dtype T | is_node(T) | sized(T))
    149         static inline void append( __queue(T) & this, T * val ) {
     96        void append( __queue(T) & this, T * val ) {
    15097                verify(this.tail != NULL);
    15198                *this.tail = val;
     
    154101
    155102        forall(dtype T | is_node(T) | sized(T))
    156         static inline T * pop_head( __queue(T) & this ) {
     103        T * pop_head( __queue(T) & this ) {
    157104                T * head = this.head;
    158105                if( head ) {
     
    167114
    168115        forall(dtype T | is_node(T) | sized(T))
    169         static inline T * remove( __queue(T) & this, T ** it ) {
     116        T * remove( __queue(T) & this, T ** it ) {
    170117                T * val = *it;
    171118                verify( val );
Note: See TracChangeset for help on using the changeset viewer.