The Queue Class Details

Below are provided the details of the methods and properties of the queue buffer class.

class circular_buffer_numpy.queue.Queue(shape=(20, 2), dtype='float64')[source]

queue data structure implemented using numpy arrays.

Variables
  • rear – initial value: -1

  • length – initial value: 0

property data_shape

tuple: returns the shape of the circular buffer

dequeue(N=0)[source]

remove (access) an item from the queue. return N points from the back and move rear_pointer

Parameters
N :: integer
Returns
array :: numpy array

Examples

>>> data = circual_buffer.Queue.dequeue()
property dtype

dtype: returns the dtype of the circular buffer

enqueue(data)[source]

add (store) an item to the queue.

Parameters
data :: (numpy array)

data to append

Returns
None

Examples

>>> queue = circular_buffer_numpy.queue.Queue(shape = (10,4)
>>> from numpy.random import random
>>> rand_arr = random(size=(6,4))
>>> queue.enqueue(rand_arr)
>>> queue.length
6
property front

points at the front element in the queue. first one to dequeue.

property isempty

Checks if the queue is empty.

Parameters
None
Returns
flag :: boolean

Examples

>>> queue = Queue()
>>> queue.isempty()
    True
property isfull

Checks if the queue is full.

Parameters
None
Returns
flag :: boolean

Examples

>>> queue = Queue()
>>> queue.isfull()
    False
peek_all()[source]

peeks into the queue and return entire buffer sorted. The last entry will be the end of the queue.

peek_first_N(N)[source]

return first N entries in the queue. [first to go].

Parameters
N: (integer)

number of points requested

Returns
arrayarray_like

Examples

>>> from circular_buffer_numpy.queue import Queue
queue = Queue((100,2), dtype = 'int16')
queue.length = 5
queue.peek_first_N(N = 5)
peek_front()[source]

Gets the element at the front of the queue without removing it.

peek_i_j(i, j)[source]

returns buffer between indices i and j (including index i) if j < i, it assumes that buffer wrapped around and will give information accordingly. NOTE: the user needs to pay attention to the order at which indices are passed NOTE: index i cannot be -1 otherwise it will return empty array

peek_last_N(N)[source]

return last N entries in the queue. [last to go].

algorithms: 1. find i (right index in the numpy array) 2. find j (left index in the numpy array)

Parameters
N: (integer)

number of points requested

Returns
arrayarray_like

Examples

>>> circual_buffer.Queue.peek_last_N()
peek_rear()[source]

Gets the element at the rear of the queue without removing it.

reset()[source]

resets the queue by setting front and back equal to 0.

Parameters
None
Returns
None

Examples

>>> queue = Queue()
>>> queue.reset()
reshape(shape, dtype=None)[source]

reshapes buffer but also resets it. Takes two parameters as input, shape and dtype. dtype atribute can be passed if dtype of the queue needs changes

Parameters
shape :: tuple

new shape of the queue

dtype :: numpy datatype string

new data type

Returns
None

Examples

>>> queue = Queue(shape = (100,2))
>>> queue.reshape(shape = (1000,2))
>>> queue.shape
    (1000,2)
property shape

tuple: returns the shape of the circular buffer

property size

integer: returns the size of the circular buffer