Skip to content
This repository was archived by the owner on Mar 23, 2023. It is now read-only.

Implement complex hash.#293

Merged
trotterdylan merged 1 commit intogoogle:masterfrom
corona10:complexhash
Apr 24, 2017
Merged

Implement complex hash.#293
trotterdylan merged 1 commit intogoogle:masterfrom
corona10:complexhash

Conversation

@corona10
Copy link
Copy Markdown
Contributor

@corona10 corona10 commented Apr 23, 2017

Implement complex hash.

@corona10 corona10 changed the title Implement complex hash. [WIP]Implement complex hash. Apr 23, 2017
@corona10 corona10 changed the title [WIP]Implement complex hash. Implement complex hash. Apr 23, 2017
@corona10
Copy link
Copy Markdown
Contributor Author

@trotterdylan Ready for review.

Comment thread runtime/complex.go Outdated
type Complex struct {
Object
value complex128
hash int
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I question whether caching the hash value has much value. Note that CPython does not cache it for complex or float. Perhaps we should remove the caching in float until there's a good reason to add it.

Note that strings are good candidates for caching since a) the length of the string can be very long (amortizes the runtime of hash(s)) and b) many commonly used strings (e.g. attribute names) are interned meaning that the cache is highly effective.

Neither of these factors apply to float or complex.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@trotterdylan Yes, I agree with you. It is not a heavy operation to caching it.

@corona10
Copy link
Copy Markdown
Contributor Author

@trotterdylan PTAL

Copy link
Copy Markdown
Contributor

@trotterdylan trotterdylan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR looks great! Thanks for putting it together. Just a couple minor style nitpicks.

Comment thread runtime/complex.go Outdated
// NewComplex returns a new Complex holding the given complex value.
func NewComplex(value complex128) *Complex {
return &Complex{Object{typ: ComplexType}, value}
return &Complex{Object: Object{typ: ComplexType}, value: value}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is no longer necessary

Comment thread runtime/complex.go Outdated

func complexHash(f *Frame, o *Object) (*Object, *BaseException) {
v := toComplexUnsafe(o)
hashreal := hashFloat(real(v.Value()))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style nit: I don't think you can reduce the number of temporaries without affecting readability too much.

@corona10
Copy link
Copy Markdown
Contributor Author

@trotterdylan Thank you for your review! I updated with you pointed it.

Copy link
Copy Markdown
Contributor

@trotterdylan trotterdylan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the changes. This looks great!

@trotterdylan trotterdylan merged commit 6841671 into google:master Apr 24, 2017
@corona10 corona10 deleted the complexhash branch April 24, 2017 05:45
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants