-
Notifications
You must be signed in to change notification settings - Fork 230
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: minted early tracking #11066
Merged
Merged
fix: minted early tracking #11066
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -338,7 +338,6 @@ export const prepareAdvancerKit = ( | |
e, | ||
); | ||
} | ||
tmpReturnSeat.exit(); | ||
}, | ||
/** | ||
* @param {Error} error | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
import { Fail } from '@endo/errors'; | ||
|
||
/** | ||
* @import {Key} from '@endo/patterns'; | ||
*/ | ||
|
||
// TODO provide something like this in a more common place, perhaps as a BagStore | ||
/** | ||
* Creates a bag (multi-set) API that wraps a MapStore where values are counts. | ||
* | ||
* @template {Key} K | ||
* @param {MapStore<K, number>} mapStore | ||
*/ | ||
export const asMultiset = mapStore => | ||
harden({ | ||
/** | ||
* Add an item to the bag, incrementing its count. | ||
* | ||
* @param {K} item The item to add | ||
* @param {number} [count] How many to add (defaults to 1) | ||
*/ | ||
add: (item, count = 1) => { | ||
if (count <= 0) { | ||
throw Fail`Cannot add a non-positive count ${count} to bag`; | ||
} | ||
|
||
if (mapStore.has(item)) { | ||
const currentCount = mapStore.get(item); | ||
mapStore.set(item, currentCount + count); | ||
} else { | ||
mapStore.init(item, count); | ||
} | ||
}, | ||
|
||
/** | ||
* Remove an item from the bag, decrementing its count. If count reaches | ||
* zero, the item is removed completely. | ||
* | ||
* @param {K} item The item to remove | ||
* @param {number} [count] How many to remove (defaults to 1) | ||
* @returns {boolean} Whether the removal was successful | ||
* @throws {Error} If trying to remove more items than exist | ||
*/ | ||
remove: (item, count = 1) => { | ||
if (count <= 0) { | ||
throw Fail`Cannot remove a non-positive count ${count} from bag`; | ||
} | ||
|
||
if (!mapStore.has(item)) { | ||
return false; | ||
} | ||
|
||
const currentCount = mapStore.get(item); | ||
if (currentCount < count) { | ||
throw Fail`Cannot remove ${count} of ${item} from bag; only ${currentCount} exist`; | ||
} | ||
|
||
if (currentCount === count) { | ||
mapStore.delete(item); | ||
} else { | ||
mapStore.set(item, currentCount - count); | ||
} | ||
return true; | ||
}, | ||
|
||
/** | ||
* Get the count of an item in the bag. | ||
* | ||
* @param {K} item The item to check | ||
* @returns {number} The count (0 if not present) | ||
*/ | ||
count: item => { | ||
return mapStore.has(item) ? mapStore.get(item) : 0; | ||
}, | ||
|
||
/** | ||
* Check if the bag contains at least one of the item. | ||
* | ||
* @param {K} item The item to check | ||
* @returns {boolean} Whether the item is in the bag | ||
*/ | ||
has: item => { | ||
return mapStore.has(item); | ||
}, | ||
|
||
/** | ||
* Get all unique items in the bag. | ||
* | ||
* @returns {Iterable<K>} Iterable of unique items | ||
*/ | ||
keys: () => { | ||
return mapStore.keys(); | ||
}, | ||
|
||
/** | ||
* Get all entries (item, count) in the bag. | ||
* | ||
* @returns {Iterable<[K, number]>} Iterable of [item, count] pairs | ||
*/ | ||
entries: () => { | ||
return mapStore.entries(); | ||
}, | ||
|
||
/** | ||
* Get the total number of unique items in the bag. | ||
* | ||
* @returns {number} Number of unique items | ||
*/ | ||
size: () => { | ||
return mapStore.getSize(); | ||
}, | ||
|
||
/** | ||
* Remove all items from the bag. | ||
*/ | ||
clear: () => { | ||
mapStore.clear(); | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably should check that
count
is a Nat ?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm using number and Nat is bigint
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, but we should still enforce that this in an integer, not any float.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually it's not just floats, but any NaN or non number values that will cause unexpected value for current count.