-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Comments
@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. |
@walkmiao I think I see your point, I'll implement a fix for all structures that might have such scenarios |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 }
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
}`
The text was updated successfully, but these errors were encountered: