kernel/src/runtime/Vector.h
/**
         * Inserts an item at the given index.
         *
         * @param index Index to add the item at, in the range of [0, size].
         */
Inserts an item at the given index.
@param index Index to add the item at, in the range of [0, size].
Inserts an item at the given index . @param index Index to add the item at in the range of [ 0 size ] .
void insert(const size_t index, const T value) {
            REQUIRE(index <= this->numAllocated, "vector access out of bounds: %zu", index);
            if(index == this->numAllocated) {
                return this->push_back(value);
            }
            else {
                this->ensureStorage();
                const auto toMove = (this->numAllocated - index);
                if(toMove) {
                    for(size_t j = (toMove - 1); j; j--) {
                        this->storage[index + j + 1] = this->storage[index + j];
                    }
                }
                this->storage[index] = value;
                this->numAllocated++;
            }
        }
void insert ( const size_t index , const T value ) { REQUIRE ( index <= this -> numAllocated , " " , index ) ; if ( index == this -> numAllocated ) { return this -> push_back ( value ) ; } else { this -> ensureStorage ( ) ; const auto toMove = ( this -> numAllocated - index ) ; if ( toMove ) { for ( size_t j = ( toMove - 1 ) ; j ; j -- ) { this -> storage [ index + j + 1 ] = this -> storage [ index + j ] ; } } this -> storage [ index ] = value ; this -> numAllocated ++ ; } }
Inserts an item at the given index.
Inserts an item at the given index .
// end of vector case // we'll have to shift items // ensure there's space for one more item // then shift items down and insert at desired index // shift items down, but do it in reverse //memmove(&this->storage[index+1], &this->storage[index], toMove * sizeof(T)); // update counts