Skip to content

Instantly share code, notes, and snippets.

@yefim
Last active November 17, 2020 03:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yefim/4063801 to your computer and use it in GitHub Desktop.
Save yefim/4063801 to your computer and use it in GitHub Desktop.
Queue implementation in CoffeeScript
class Q
constructor: (@bound) ->
@offset = 0
@length = 0
@data = []
enqueue: (value) ->
return undefined if @length == @bound
@data.push value
++@length
dequeue: ->
return undefined if !@length
value = @data[@offset]
@offset++
@length--
return value
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment