Skip to content

Instantly share code, notes, and snippets.

@tauraamui
Created September 28, 2022 12:55
Show Gist options
  • Save tauraamui/f7a12565ee3ee16a8cb6c509b468243d to your computer and use it in GitHub Desktop.
Save tauraamui/f7a12565ee3ee16a8cb6c509b468243d to your computer and use it in GitHub Desktop.
// Internal growinh procedure
_grow :: proc(q: ^$Q/Queue($T), min_capacity: uint = 0) -> bool {
new_capacity := max(min_capacity, uint(8), uint(builtin.len(q.data))*2)
n := uint(builtin.len(q.data))
builtin.resize(&q.data, int(new_capacity)) or_return
if q.offset + q.len > n {
diff := n - q.offset
copy(q.data[new_capacity-diff:], q.data[q.offset:][:diff])
q.offset += new_capacity - n
}
return true
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment