-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsqueue.h
More file actions
91 lines (75 loc) · 1.65 KB
/
squeue.h
File metadata and controls
91 lines (75 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#ifndef __DATA_STRUCT_QUEUE_H__
#define __DATA_STRUCT_QUEUE_H__
namespace ds
{
template<typename T, size_t N>
class squeue_t
{
public:
squeue_t()
{
m_head = m_tail = 0;
}
squeue_t(const squeue_t& s)
{
*this = s;
}
~squeue_t()
{
}
void clear()
{
m_head = m_tail = 0;
}
squeue_t& operator = (const squeue_t& s)
{
m_head = s.m_head;
m_tail = s.m_tail;
for(size_t x = m_head; x < m_tail; ++ x)
{
m_data[x] = s.m_data[x];
}
}
bool empty()
{
return (m_head == m_tail);
}
bool full()
{
return (m_head == N);
}
size_t count()
{
return (m_head - m_tail);
}
T& alloc()
{
size_t x = m_head ++;
return m_data[x];
}
T& front()
{
return m_data[m_tail];
}
void pop_front()
{
++ m_tail;
}
void print()
{
printf("[(%s:%s:%d) ++++]\n", __FILE__, __PRETTY_FUNCTION__, __LINE__);
printf("[m_head(%zu)]\n", m_head);
printf("[m_tail(%zu)]\n", m_tail);
for (size_t x = m_tail; x < m_head; ++ x)
{
m_data[x].print();
}
printf("[(%s:%s:%d) ----]\n", __FILE__, __PRETTY_FUNCTION__, __LINE__);
}
private:
T m_data[N];
size_t m_head;
size_t m_tail;
};
}
#endif