Skip to content

add slice operation functions #40

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open

add slice operation functions #40

wants to merge 6 commits into from

Conversation

gammazero
Copy link
Owner

@gammazero gammazero commented Feb 14, 2025

The following functions have been added to operate on slices of values:

  • AppendToSlice(out []T) []T
  • CopyInSlice([]T)
  • CopyOutSlice([]T) int

Are these worth adding to Deque?

AppendToSlice

out = q.AppendToSlice(out) 

is an efficient shortcut for

for i := 0; i < q.Len(); i++ {
     x = append(out, q.At(i))
}

CopyInSlice

q.CopyInSlice(in)

is an efficient shortcut for

q.Clear()
for i := range in { 
    q.PushBack(in[i])
}

CopyOutSlice

n := q.CopyOutSlice(out)

is an efficient shortcut for

n := min(len(out), q.Len()) 
for i := 0; i < n; i++ {
    out[i] = q.At(i)
}

Copy

n := b.Copy(a)

is an efficient shortcut for

b.Clear()
n := a.Len()
b.Grow(n))
for i := 0; i < n; i++ {
    b.PushBack(a.At(i))
}

Replaces #37

- AppendTo
- CopyIn
- CopyOut
@gammazero gammazero marked this pull request as ready for review March 8, 2025 05:37
@gammazero gammazero changed the title add Replace function add slice operation functions Mar 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant