Skip to content

Conversation

karastojko
Copy link

No description provided.

@@ -33,6 +33,26 @@ export default class TinyQueue {
return this.data[0];
}

update(newValue, criteria) {
Copy link

Choose a reason for hiding this comment

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

Maybe

update(newValue, criteria) {
    const pos = this.data.findIndex(criteria);
    if (pos < 0) {
        return false;
    }

    this.data[pos] = newValue;
    
    const childPos = (pos << 1) + 1;
    const needsDown = (pos === 0 || (childPos < this.length && this.compare(newValue, this.data[childPos]) > 0));
    
    this[needsDown ? '_down' : '_up'](pos);

    return true;
}

@@ -1,4 +1,5 @@
export declare type Comparator<T> = (a: T, b: T) => number;
export declare type Criteria<T> = (val: T) => boolean;
Copy link

Choose a reason for hiding this comment

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

Suggested change
export declare type Criteria<T> = (val: T) => boolean;
export declare type Criteria<T> = (val: T, index: number, values: T[]) => boolean;

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

Successfully merging this pull request may close these issues.

2 participants