Git Product home page Git Product logo

cqueue's Introduction

cqueue

circular buffer implementation in golang using linked-list

GoDoc

#####Installation

go get github.com/pravj/cqueue

A circular buffer structure

// CQueue represents a circular buffer data structure
type CQueue struct {
  // size limit of the buffer
  size int 
  // occupied size of the buffer
  Length int 
  // list containing all the buffer elements
  Queue *list.List
  // element at the front-side of the buffer
  Head *list.Element
  // element at the back-side of the buffer
  Tail *list.Element
  // middleware function to call when buffer overflows
  overflow func()
}

#####Package API

  • Accessor Methods
    • Value
    • IsFull
    • IsEmpty
  • Mutator Methods
    • Push
    • Pop

#####Usage

import (
  "fmt"
  "github.com/pravj/cqueue"
)

// Alert is the middleware function to call
// in case of buffer overflow
//
// Leave its content blank if you don't want a middleware
func Alert() {
  fmt.Println("Buffer Overflow")
}

func main() {
  args := map[string]interface{}{"size":3, "middleware": Alert}
  cq := cqueue.New(args) // [- - -]
  
  cq.Push(4) // [4 - -]
  cq.Push(4) // [4 4 -]
  cq.Push(5) // [4 4 5]
  cq.Push(6) // [4 5 6] will invoke the middleware function also
  cq.Pop()   // [5 6 -]
  cq.Push(7) // [5 6 7]
  cq.Pop()   // [6 7 -]
  cq.Pop()   // [7 - -]
  cq.Pop()   // [- - -]
  cq.Pop()   // error "cqueue: buffer is empty"
}

#####TODO

  • Test Suite
  • Distributed Locking on buffer operations

Made by Pravendra Singh

cqueue's People

Contributors

pravj avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  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.