Skip to content
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

Why not just use list.elemens = append(list.elements, ...values)? #14

Closed
github-actions bot opened this issue Jul 13, 2022 · 1 comment
Closed
Labels

Comments

@github-actions
Copy link

Why not just use list.elemens = append(list.elements, ...values)?

https://github.com/golang/go/blob/master/src/runtime/slice.go

// TODO: Why not just use list.elemens = append(list.elements, ...values)?

	shrinkFactor = float32(0.25) // shrink when size is 25% of capacity (0 means never shrink)
)

// New instantiates a new list and adds the passed values, if any, to the list.
func New[T any](values ...T) *List[T] {
	list := &List[T]{}
	if len(values) > 0 {
		list.PushBack(values...)
	}
	return list
}

// NewFromSLice instantiates a new list containing the provided slice.
func NewFromSlice[T any](slice []T) *List[T] {
	list := &List[T]{elements: slice, size: len(slice)}
	return list
}

// Add appends a value at the end of the list.
func (list *List[T]) PushBack(values ...T) {
	// TODO: Why not just use list.elemens = append(list.elements, ...values)?
	// https://github.com/golang/go/blob/master/src/runtime/slice.go
	list.growBy(len(values))
	for _, value := range values {
		list.elements[list.size] = value

5f13fa0c5b83e523cacbcc2c2244deed2b53f9fa

@github-actions
Copy link
Author

Closed in fdc27db

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Done
Development

No branches or pull requests

0 participants