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

Added map and join methods. Also made negative indices work for get #26

Merged
merged 2 commits into from
Mar 26, 2020

Conversation

dfellis
Copy link
Contributor

@dfellis dfellis commented Nov 18, 2017

Hi, thanks for getting this project started for a circular buffer with an Array interface!

For my own usage, I needed map and join, so at first I just did a toArray() and did them, but would prefer eliminating the extra temporary object, so I've implemented the parts I need and wrote tests for them.

While writing the tests I noticed that the get function doesn't allow negative indexing, which seems useful for Circular Buffers in a way that it wouldn't be for a normal Array, so I also added a negative-capable modulus function and used it there.

@dfellis
Copy link
Contributor Author

dfellis commented Nov 18, 2017

...and I just realized you're using tabs, let me fix the formatting.

@bubbakk
Copy link

bubbakk commented Feb 21, 2020

Good morning.
Thank you for this implementation: really useful, reach of methods and well implemented!

I needed a little improvement to last() method: maybe you can like it.
Now last() accepts an optional argument: if passed returns last n inserted values, not only one.
I tried to conform added code to your coding style.

Here it is:

last : function (arg) {
  if (typeof arg === 'undefined' || arg === 1)
    return this.data[this.end];
  else if (typeof arg === 'number') {
    arg = Math.abs(parseInt(arg));
    let result = new Array(arg);
    for (let index = 0; index < arg; index++) {
      let idx = this.end - index;
      if ( idx >= 0 ) result[index] = this.data[idx];
      if ( idx < 0 ) result[index] = this.data[this.size - 1 + ((idx + 1) % this.size)];
    }
    return result;
  }
},

@dfellis
Copy link
Contributor Author

dfellis commented Feb 21, 2020

Hi @bubbakk it appears this repository has been abandoned (I wrote this PR over 2 years ago) and I removed the usage of the library, even with these improvements, from the repository that was depending on it.

If you're willing to maintain the codebase yourself, I would recommend forking off of this repository or my fork and then you can add your function there and refactor the code style to be more to your liking.

I left the PR up because @trevnorris does seem to still be active and this is the #1 repository listed on his Github page: https://github.com/trevnorris so I thought he might notice it when taking a trip down memory lane.

@trevnorris trevnorris merged commit 3c4aa55 into trevnorris:master Mar 26, 2020
@trevnorris
Copy link
Owner

@dfellis It's been a while. Didn't realize people still used this library. Thanks for the PR. It's now been squashed and merged.

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.

3 participants