Giter VIP home page Giter VIP logo

buffer's Introduction

Buffer

This is buffer based on a circular singly linked list implementation that follows the itterator interface, being a drop in replacement for iterable structure when you need a list. When used unbound, it acts like a queue, when used bound, will start evicting once it hits the maxSize.

Usage Deno

import Buffer from "https://deno.land/x/buffer/mod.ts";

Usage Node

npm install --save @denox/buffer
import Buffer from "@denox/buffer";

API

Initialization

The only argument is entries and it is optional, allowing prepopulating the buffer.

const queue = new Buffer(); // Creates an empty queue
const queueWithData = new Buffer(Infinity, ["value1", "value2"]); // Creates a queue with 2 entries

const buffer = new Buffer(100); // Creates an empty buffer
const bufferWithData = new Buffer(100, ["value1", "value2"]); // Creates a buffer with 2 entries

Push

Add a value to end of the buffer.

buffer.push("value");

Pop

Retrieve a value from begining of the buffer.

buffer.pop(); // "value"

Peek

Retrieve a value from begining of the buffer, similar with pop but without changing the buffer.

buffer.peek(); // "value"

Clear

Clear everything from the buffer, leaving the queue empty.

buffer.clear();

Size

Get the current size of the buffer.

buffer.size; // Number

MaxSize

Get the capacity of the buffer.

buffer.maxSize; // Number

Keys, Values, Entries

Get the iterators for keys, values or entries ordered based on the insetion.

Array.from(buffer.keys()); // [value1, value2, ...]
Array.from(buffer.values()); // [value1, value2, ...]
Array.from(buffer.entries()); // [[value1, value1], [value2, value2], ...]

ForEach

Iterate over the values in the insersion order.

buffer.forEach((value, key, buffer) => {
	//...
});

License

MIT

buffer's People

Contributors

claudiuandrei avatar

Stargazers

 avatar

Watchers

 avatar

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.