/* * This file is automaticaly generated, Please dont edit this file! */ #include int array_length( array * this ) { return this->total; } void * array_get( array * this, int index ) { if ( index >= 0 && index < this->total ){ return this->items[index]; } return NULL; } void array_set( array * this, int index, void * item ) { if ( index >= 0 && index < this->total ){ this->items[ index ] = item; } } void array_resize( array * this, int capacity ) { void * * items = realloc( this->items, sizeof( void * ) * capacity ); this->items = items; this->capacity = capacity; } void array_add( array * this, void * item ) { if ( this->capacity == this->total ){ array_resize( this, this->capacity * 2 ); } this->items[ this->total++ ] = item; } char * array_join( array * this, char * separator ) { int count = array_length( this ); text * result = text_newPointer( "" ); for (int i = 0; i < count; ++i) { char * currentPart = this->items[ i ]; if( i > 0 ) { text_append( result, separator ); } text_append( result, currentPart ); } return result->value; } void array_delete( array * this, int index ) { if ( index < 0 || index >= this->total ){ return; } this->items[index] = NULL; for ( int i = index; i < this->total - 1; i++ ) { this->items[i] = this->items[i + 1]; this->items[i + 1] = NULL; } this->total--; if ( this->total > 0 && this->total == this->capacity / 4 ){ array_resize( this, this->capacity / 2 ); } } int array_array_push( array * this, void * item ) { array_add( this, item ); return this->total; } void array_unshift( array * this, void * item ) { int length = this->total; this->total++; if ( this->capacity == this->total ){ array_resize( this, this->capacity * 2 ); } for ( int i = length - 1; i >= 0; --i ) { this->items[ i + 1 ] = this->items[ i ]; } this->items[ 0 ] = item; } void * array_pop( array * this ) { int length = this->total; int lastIndex = length - 1; void * lastItem = array_get( this, lastIndex ); array_delete( this, lastIndex ); return lastItem; } array array_new() { array instance; instance.__classIndex = 5; instance.capacity = 10; instance.total = 0; instance.items = malloc( 10000000 ); return instance; } array * array_newPointer() { struct array * pointer = malloc( sizeof ( struct array ) ); pointer->__classIndex = 5; pointer->capacity = 10; pointer->total = 0; pointer->items = malloc( 10000000 ); return pointer; }