Skip to content
This repository was archived by the owner on Mar 17, 2026. It is now read-only.

Add pow2 resize vector#553

Open
elefthei wants to merge 3 commits intomainfrom
lef/stdvector
Open

Add pow2 resize vector#553
elefthei wants to merge 3 commits intomainfrom
lef/stdvector

Conversation

@elefthei
Copy link

@elefthei elefthei commented Feb 8, 2026

A vector that doubles in length when appending more than N elements (N length), and halves in length when element count falls below N/2. Basically the C++ STL vector.


/// Resize the vector to new_size elements.
/// Preserves the first min(old_size, new_size) elements.
fn resize (#t:Type0) (v:vector t) (new_size:SZ.t{SZ.v new_size > 0})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
fn resize (#t:Type0) (v:vector t) (new_size:SZ.t{SZ.v new_size > 0})
fn resize (#t:Type0) (v:vector t) (new_size:SZ.t)

??

Lef Ioannidis and others added 2 commits February 19, 2026 21:39
Replace 3 inner boxes (arr_box, size_box, cap_box) with one outer
box wrapping a plain struct: vector t = box (vector_internal t).

- 1 heap allocation per vector instead of 3
- Simpler predicate: pts_to v vi ** A.pts_to vi.arr buf
- Cleaner mutation: write whole struct via v := new_vi
- Better C extraction (single pointer to struct)
- .fsti unchanged (vector and is_vector are abstract)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
push_back: cap unchanged when room exists, doubled when full.
pop_back: cap halved when size == cap/2 > 0, unchanged otherwise.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants