Ignore:
Timestamp:
Jan 7, 2021, 2:55:57 PM (5 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
58fe85a
Parents:
bdfc032 (diff), 44e37ef (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' into dkobets-vector

File:
1 edited

Legend:

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

    rbdfc032 reef8dfb  
    1717#include "bits/align.hfa"
    1818#include "bits/defs.hfa"
    19 
     19#include <stdio.h>
    2020//-----------------------------------------------------------------------------
    2121// Array
     
    3636        #define __small_array_t(T) __small_array(T)
    3737#else
    38         #define __small_array_t(T) struct __small_array
     38        #define __small_array_t(T) __small_array
    3939#endif
    4040
     
    146146        static inline forall( dtype T | is_node(T) ) {
    147147                void ?{}( __queue(T) & this ) with( this ) {
    148                         head{ 0p };
    149                         tail{ &head };
     148                        (this.head){ 1p };
     149                        (this.tail){ &this.head };
     150                        verify(*this.tail == 1p);
    150151                }
    151152
    152153                void append( __queue(T) & this, T * val ) with( this ) {
    153                         verify(tail != 0p);
    154                         *tail = val;
    155                         tail = &get_next( *val );
     154                        verify(this.tail != 0p);
     155                        verify(*this.tail == 1p);
     156                        *this.tail = val;
     157                        this.tail = &get_next( *val );
     158                        *this.tail = 1p;
     159                }
     160
     161                T * peek( __queue(T) & this ) {
     162                        verify(*this.tail == 1p);
     163                        T * front = this.head;
     164                        if( front != 1p ) {
     165                                verify(*this.tail == 1p);
     166                                return front;
     167                        }
     168                        verify(*this.tail == 1p);
     169                        return 0p;
    156170                }
    157171
    158172                T * pop_head( __queue(T) & this ) {
    159                         T * head = this.head;
    160                         if( head ) {
    161                                 this.head = get_next( *head );
    162                                 if( !get_next( *head ) ) {
     173                        verify(*this.tail == 1p);
     174                        T * _head = this.head;
     175                        if( _head != 1p ) {
     176                                this.head = get_next( *_head );
     177                                if( get_next( *_head ) == 1p ) {
    163178                                        this.tail = &this.head;
    164179                                }
    165                                 get_next( *head ) = 0p;
    166                         }
    167                         return head;
     180                                get_next( *_head ) = 0p;
     181                                verify(*this.tail == 1p);
     182                                verify( get_next(*_head) == 0p );
     183                                return _head;
     184                        }
     185                        verify(*this.tail == 1p);
     186                        return 0p;
    168187                }
    169188
     
    174193                        (*it) = get_next( *val );
    175194
    176                         if( tail == &get_next( *val ) ) {
    177                                 tail = it;
     195                        if( this.tail == &get_next( *val ) ) {
     196                                this.tail = it;
    178197                        }
    179198
    180199                        get_next( *val ) = 0p;
    181200
    182                         verify( (head == 0p) == (&head == tail) );
    183                         verify( *tail == 0p );
     201                        verify( (this.head == 1p) == (&this.head == this.tail) );
     202                        verify( *this.tail == 1p );
    184203                        return val;
    185204                }
    186205
    187206                int ?!=?( const __queue(T) & this, __attribute__((unused)) zero_t zero ) {
    188                         return this.head != 0;
     207                        return this.head != 1p;
    189208                }
    190209        }
     
    220239        forall(dtype T )
    221240        static inline [void] ?{}( __dllist(T) & this, * [T * & next, T * & prev] ( T & ) __get ) {
    222                 this.head{ 0p };
     241                (this.head){ 0p };
    223242                this.__get = __get;
    224243        }
     
    229248                void push_front( __dllist(T) & this, T & node ) with( this ) {
    230249                        verify(__get);
    231                         if ( head ) {
    232                                 __get( node ).next = head;
    233                                 __get( node ).prev = __get( *head ).prev;
     250                        if ( this.head ) {
     251                                __get( node ).next = this.head;
     252                                __get( node ).prev = __get( *this.head ).prev;
    234253                                // inserted node must be consistent before it is seen
    235254                                // prevent code movement across barrier
    236255                                asm( "" : : : "memory" );
    237                                 __get( *head ).prev = &node;
     256                                __get( *this.head ).prev = &node;
    238257                                T & _prev = *__get( node ).prev;
    239258                                __get( _prev ).next = &node;
     
    245264                        // prevent code movement across barrier
    246265                        asm( "" : : : "memory" );
    247                         head = &node;
     266                        this.head = &node;
    248267                }
    249268
    250269                void remove( __dllist(T) & this, T & node ) with( this ) {
    251270                        verify(__get);
    252                         if ( &node == head ) {
    253                                 if ( __get( *head ).next == head ) {
    254                                         head = 0p;
     271                        if ( &node == this.head ) {
     272                                if ( __get( *this.head ).next == this.head ) {
     273                                        this.head = 0p;
    255274                                } else {
    256                                         head = __get( *head ).next;
     275                                        this.head = __get( *this.head ).next;
    257276                                }
    258277                        }
     
    266285                        return this.head != 0;
    267286                }
     287
     288                void move_to_front( __dllist(T) & src, __dllist(T) & dst, T & node ) {
     289                        remove    (src, node);
     290                        push_front(dst, node);
     291                }
    268292        }
    269293        #undef next
Note: See TracChangeset for help on using the changeset viewer.