Rizin
unix-like reverse engineering framework and cli tools
DotZLib.CircularBuffer Class Reference

This class implements a circular buffer More...

Public Member Functions

 CircularBuffer (int capacity)
 
int Put (byte[] source, int offset, int count)
 
bool Put (byte b)
 
int Get (byte[] destination, int offset, int count)
 
int Get ()
 

Properties

int Size [get]
 

Private Attributes

int _capacity
 
int _head
 
int _tail
 
int _size
 
byte[] _buffer
 

Detailed Description

This class implements a circular buffer

Definition at line 17 of file CircularBuffer.cs.

Constructor & Destructor Documentation

◆ CircularBuffer()

DotZLib.CircularBuffer.CircularBuffer ( int  capacity)
inline

Definition at line 27 of file CircularBuffer.cs.

28  {
29  Debug.Assert( capacity > 0 );
30  _buffer = new byte[capacity];
31  _capacity = capacity;
32  _head = 0;
33  _tail = 0;
34  _size = 0;
35  }

References DotZLib.CircularBuffer._buffer, DotZLib.CircularBuffer._capacity, DotZLib.CircularBuffer._head, DotZLib.CircularBuffer._size, and DotZLib.CircularBuffer._tail.

Member Function Documentation

◆ Get() [1/2]

int DotZLib.CircularBuffer.Get ( )
inline

Definition at line 72 of file CircularBuffer.cs.

73  {
74  if (Size == 0)
75  return -1;
76 
77  int result = (int)_buffer[_head++ % _capacity];
78  --_size;
79  return result;
80  }
static int
Definition: sfsocketcall.h:114

References DotZLib.CircularBuffer._buffer, DotZLib.CircularBuffer._capacity, DotZLib.CircularBuffer._head, DotZLib.CircularBuffer._size, int, and DotZLib.CircularBuffer.Size.

◆ Get() [2/2]

int DotZLib.CircularBuffer.Get ( byte[]  destination,
int  offset,
int  count 
)
inline

Definition at line 61 of file CircularBuffer.cs.

62  {
63  int trueCount = Math.Min(count,Size);
64  for (int i = 0; i < trueCount; ++i)
65  destination[offset + i] = _buffer[(_head+i) % _capacity];
66  _head += trueCount;
67  _head %= _capacity;
68  _size -= trueCount;
69  return trueCount;
70  }
lzma_index ** i
Definition: index.h:629
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void count
Definition: sflib.h:98
voidpf uLong offset
Definition: ioapi.h:144

References DotZLib.CircularBuffer._buffer, DotZLib.CircularBuffer._capacity, DotZLib.CircularBuffer._head, DotZLib.CircularBuffer._size, count, i, and DotZLib.CircularBuffer.Size.

◆ Put() [1/2]

bool DotZLib.CircularBuffer.Put ( byte  b)
inline

Definition at line 51 of file CircularBuffer.cs.

52  {
53  if (Size == _capacity) // no room
54  return false;
55  _buffer[_tail++] = b;
56  _tail %= _capacity;
57  ++_size;
58  return true;
59  }
#define b(i)
Definition: sha256.c:42

References DotZLib.CircularBuffer._buffer, DotZLib.CircularBuffer._capacity, DotZLib.CircularBuffer._size, DotZLib.CircularBuffer._tail, b, and DotZLib.CircularBuffer.Size.

◆ Put() [2/2]

int DotZLib.CircularBuffer.Put ( byte[]  source,
int  offset,
int  count 
)
inline

Definition at line 39 of file CircularBuffer.cs.

40  {
41  Debug.Assert( count > 0 );
42  int trueCount = Math.Min(count, _capacity - Size);
43  for (int i = 0; i < trueCount; ++i)
45  _tail += trueCount;
46  _tail %= _capacity;
47  _size += trueCount;
48  return trueCount;
49  }
const char * source
Definition: lz4.h:699

References DotZLib.CircularBuffer._buffer, DotZLib.CircularBuffer._capacity, DotZLib.CircularBuffer._size, DotZLib.CircularBuffer._tail, count, i, DotZLib.CircularBuffer.Size, and source.

Member Data Documentation

◆ _buffer

byte [] DotZLib.CircularBuffer._buffer
private

◆ _capacity

int DotZLib.CircularBuffer._capacity
private

◆ _head

int DotZLib.CircularBuffer._head
private

◆ _size

int DotZLib.CircularBuffer._size
private

◆ _tail

int DotZLib.CircularBuffer._tail
private

Property Documentation

◆ Size

int DotZLib.CircularBuffer.Size
get

Definition at line 37 of file CircularBuffer.cs.

37 { get { return _size; } }

Referenced by DotZLib.CircularBuffer.Get(), and DotZLib.CircularBuffer.Put().


The documentation for this class was generated from the following file: