A JavaScript implementation of the Flippy Flop data structure.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
.gitignore
FlippyFloppyLogo.png
LICENSE
README.md
main.js
package.json

README.md

ff-js

A JavaScript implementation of the Flippy Flop data structure.

Background

A Flippy Flop is an unpredictable data structure. Flip (insertion) and flop (removal) operations succeed at random.

Usage

As you'll see in the example below, the Flippy Flop is sufficiently unpredictable.

Node.js

var FlippyFlop = require("flippy-flop");

var ff = new FlippyFlop();

// Attempt to insert a value
ff.flip(5);

// Could be 5, or undefined if the flip call failed
var flop1 = ff.flop();

// Could be 5 if the flop call didn't remove the value, or undefined if the flip call failed
var flop2 = ff.flop();

// However, it's easy to verify the number of elements in a FlippyFlop
var count = ff.count();

Contact

You can most easily reach me on twitter @_Shakeel.

License

This project is licensed under the terms of the MIT license.