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

Fix handling of null and undefined in EdgeMap #65

Merged
merged 1 commit into from
Oct 10, 2016
Merged

Conversation

sharwell
Copy link
Member

This pull request addresses cases where undefined and null are being used in EdgeMap<T> without being part of type signatures.

📝 Strict null checks are currently disabled, but we're working to change that. See #26.


// @NotNull
put(key: number, /*@Nullable*/ value: T): EdgeMap<T>;
put(key: number, value: T): EdgeMap<T>;
Copy link
Member Author

Choose a reason for hiding this comment

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

📝 The only cases where a "nullable" value was passed to this method are in ArrayEdgeMap. Rather than make the parameter T | undefined here, I updated the argument in ArrayEdgeMap.put to allow those cases specifically when working with the concrete implementation ArrayEdgeMap.

@@ -49,15 +49,15 @@ export class SingletonEdgeMap<T> extends AbstractEdgeMap<T> {
this.value = value;
} else {
this.key = 0;
this.value = null;
this.value = undefined;
Copy link
Member Author

Choose a reason for hiding this comment

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

💭 I know the value is already undefined. Does it help clarity to keep this assignment here and/or do we gain a performance benefit by removing the assignment?

@@ -88,17 +88,17 @@ export class SparseEdgeMap<T> extends AbstractEdgeMap<T> {

@Override
containsKey(key: number): boolean {
return this.get(key) != null;
return !!this.get(key);
Copy link
Member Author

Choose a reason for hiding this comment

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

📝 The form seen here is idiomatic C++. Since JavaScript behaves the same way, would it be idiomatic JavaScript/TypeScript as well? Also, would !!this.get(key) or this.get(key) !== undefined be faster in practice?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes, I think !! is widely accepted to convert a Booleanish to Boolean.

@BurtHarris BurtHarris merged commit 403cd82 into master Oct 10, 2016
@sharwell sharwell deleted the map-undefined branch October 10, 2016 21:30
@BurtHarris BurtHarris removed their assignment Oct 11, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants