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

some problem of contains #204

Closed
walkmiao opened this issue Apr 16, 2022 · 4 comments
Closed

some problem of contains #204

walkmiao opened this issue Apr 16, 2022 · 4 comments

Comments

@walkmiao
Copy link

  1. Add will trigger resize,length and cap is cap value
    func (list *List) resize(cap int) { newElements := make([]interface{}, cap, cap) copy(newElements, list.elements) list.elements = newElements }

  2. Contains will iterate default nil value,list.elements is the resized newElements。
    `func (list *List) Contains(values ...interface{}) bool {

    for _, searchValue := range values {
    found := false
    for _, element := range list.elements {
    if element == searchValue {
    found = true
    break
    }
    }
    if !found {
    return false
    }
    }
    return true
    }`

@emirpasic
Copy link
Owner

@walkmiao what seems to be the problem?

@walkmiao
Copy link
Author

@walkmiao what seems to be the problem?

if values contains a value = nil and list.elements contains nil,but we never add nil to list.elements.
another one, contains iterate cap(elements)-len(elements) times meaningless operation?

@emirpasic
Copy link
Owner

@walkmiao I think I see your point, I'll implement a fix for all structures that might have such scenarios

@emirpasic
Copy link
Owner

@walkmiao thanks for reporting the issue.
This has been resolved in v1.18.1 by #205

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

No branches or pull requests

2 participants