Skip to content
This repository was archived by the owner on Apr 6, 2024. It is now read-only.
This repository was archived by the owner on Apr 6, 2024. It is now read-only.

[Feature Request] Apply more efficient allocate algorithm in vector #1

Open
@iosmanthus

Description

@iosmanthus

Currently, our vector is too simple and have really bad performance in push/pop because we need to reallocate resource and execute memcpy when we add a new element to the end of the vector. Dynamic tables described in CLRS may be feasible in this situation.

template <typename T>
void Vec<T>::push(T data)
{
T* new_buf = new T[this->len + 1];
std::copy(this->buf, this->buf + this->len, new_buf);
new_buf[this->len] = data;
delete[] this->buf;
this->buf = new_buf;
this->len++;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    collectionsCollections typeeasyissue that easy to solveenhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions