Skip to content

CircularBuffer peekLast undefined #223

@magicdawn

Description

@magicdawn

using package v0.39.7

const q = new CircularBuffer<boolean>(Array, 2)
{
  q.push(true)
  q.push(true)
  q.push(true)
  // q.push(true)
}
q.push(false)
q.push(true)
console.log(q.toArray()) // [false, true]
console.log(q.peekFirst()) // false
console.log(q.peekLast()) // undefined

const q = new CircularBuffer<boolean>(Array, 2)
{
  q.push(true)
  q.push(true)
  q.push(true)
  q.push(true) // <--- this line is uncommented
}
q.push(false)
q.push(true)
console.log(q.toArray()) // [false, true]
console.log(q.peekFirst()) // false
console.log(q.peekLast()) // true

Maybe https://github.com/Yomguithereal/mnemonist/blob/0.39.7/fixed-deque.js#L138-L139 should be ?

-if (index > this.capacity)
+if (index >= this.capacity)
    index -= this.capacity;

or I got something misunderstanding ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions