Coder Social home page Coder Social logo

trial.circular's People

Contributors

breese avatar mtnpke avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

trial.circular's Issues

API for bulk data operations

Hi,

thanks for this nice project! It was really easy to integrate and use and was the only circular buffer API that fulfilled my needs of being able to bulk resize.

Regarding bulk insertion and removal operations, I was wondering if there would be an option to offer some kind of higher-level API. You offer the segment views, but it is a bit clunky to put in user code and requires some knowledge of the internals of the buffer. I haven't found a better way, but of course it might also be that I just missed it.

For example, to insert a block of data, I currently use:

// add `std::span<std::byte> data` to the end of `circular::span<std::byte> q`
auto copyDestFirstSeg{q.first_unused_segment()};
auto copyDestLastSeg{q.last_unused_segment()};
q.expand_back(data.size());
const auto bytesInFirstSeg{std::min(data.size(), copyDestFirstSeg.size())};
const auto bytesInLastSeg{data.size() - bytesInFirstSeg};
std::copy_n(data.begin(), bytesInFirstSeg, copyDestFirstSeg.begin());
if (bytesInLastSeg > 0) {
	std::copy_n(data.begin() + bytesInFirstSeg, bytesInLastSeg, copyDestLastSeg.begin());
}

Could operations like this be added to the buffer or maybe as a free-standing function? I can imagine it is quite common to want to do this with a circular buffer and I guess it is also the reason you provide the segment queries in the first place.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.