Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mpd
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Иван Мажукин
mpd
Commits
3d4f588a
Commit
3d4f588a
authored
Mar 15, 2014
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
util/CircularBuffer: rename GetSize() to GetCapacity()
parent
8f74bf31
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
22 deletions
+24
-22
CircularBuffer.hxx
src/util/CircularBuffer.hxx
+22
-22
TestCircularBuffer.hxx
test/TestCircularBuffer.hxx
+2
-0
No files found.
src/util/CircularBuffer.hxx
View file @
3d4f588a
...
@@ -65,18 +65,18 @@ protected:
...
@@ -65,18 +65,18 @@ protected:
*/
*/
size_type
tail
;
size_type
tail
;
const
size_type
size
;
const
size_type
capacity
;
const
pointer_type
data
;
const
pointer_type
data
;
public
:
public
:
constexpr
CircularBuffer
(
pointer_type
_data
,
size_type
_
size
)
constexpr
CircularBuffer
(
pointer_type
_data
,
size_type
_
capacity
)
:
head
(
0
),
tail
(
0
),
size
(
_size
),
data
(
_data
)
{}
:
head
(
0
),
tail
(
0
),
capacity
(
_capacity
),
data
(
_data
)
{}
CircularBuffer
(
const
CircularBuffer
&
other
)
=
delete
;
CircularBuffer
(
const
CircularBuffer
&
other
)
=
delete
;
protected
:
protected
:
constexpr
size_type
Next
(
size_type
i
)
const
{
constexpr
size_type
Next
(
size_type
i
)
const
{
return
i
+
1
==
size
return
i
+
1
==
capacity
?
0
?
0
:
i
+
1
;
:
i
+
1
;
}
}
...
@@ -86,8 +86,8 @@ public:
...
@@ -86,8 +86,8 @@ public:
head
=
tail
=
0
;
head
=
tail
=
0
;
}
}
size_type
GetSize
()
const
{
constexpr
size_type
GetCapacity
()
const
{
return
size
;
return
capacity
;
}
}
constexpr
bool
IsEmpty
()
const
{
constexpr
bool
IsEmpty
()
const
{
...
@@ -103,15 +103,15 @@ public:
...
@@ -103,15 +103,15 @@ public:
* When you are finished, call Append().
* When you are finished, call Append().
*/
*/
Range
Write
()
{
Range
Write
()
{
assert
(
head
<
size
);
assert
(
head
<
capacity
);
assert
(
tail
<
size
);
assert
(
tail
<
capacity
);
size_type
end
=
tail
<
head
size_type
end
=
tail
<
head
?
head
-
1
?
head
-
1
/* the "head==0" is there so we don't write
/* the "head==0" is there so we don't write
the last cell, as this situation cannot be
the last cell, as this situation cannot be
represented by head/tail */
represented by head/tail */
:
size
-
(
head
==
0
);
:
capacity
-
(
head
==
0
);
return
Range
(
data
+
tail
,
end
-
tail
);
return
Range
(
data
+
tail
,
end
-
tail
);
}
}
...
@@ -121,15 +121,15 @@ public:
...
@@ -121,15 +121,15 @@ public:
* to the buffer returned by Write().
* to the buffer returned by Write().
*/
*/
void
Append
(
size_type
n
)
{
void
Append
(
size_type
n
)
{
assert
(
head
<
size
);
assert
(
head
<
capacity
);
assert
(
tail
<
size
);
assert
(
tail
<
capacity
);
assert
(
n
<
size
);
assert
(
n
<
capacity
);
assert
(
tail
+
n
<=
size
);
assert
(
tail
+
n
<=
capacity
);
assert
(
head
<=
tail
||
tail
+
n
<
head
);
assert
(
head
<=
tail
||
tail
+
n
<
head
);
tail
+=
n
;
tail
+=
n
;
if
(
tail
==
size
)
{
if
(
tail
==
capacity
)
{
assert
(
head
>
0
);
assert
(
head
>
0
);
tail
=
0
;
tail
=
0
;
}
}
...
@@ -140,24 +140,24 @@ public:
...
@@ -140,24 +140,24 @@ public:
* writable, to allow modifications while parsing.
* writable, to allow modifications while parsing.
*/
*/
Range
Read
()
{
Range
Read
()
{
assert
(
head
<
size
);
assert
(
head
<
capacity
);
assert
(
tail
<
size
);
assert
(
tail
<
capacity
);
return
Range
(
data
+
head
,
(
tail
<
head
?
size
:
tail
)
-
head
);
return
Range
(
data
+
head
,
(
tail
<
head
?
capacity
:
tail
)
-
head
);
}
}
/**
/**
* Marks a chunk as consumed.
* Marks a chunk as consumed.
*/
*/
void
Consume
(
size_type
n
)
{
void
Consume
(
size_type
n
)
{
assert
(
head
<
size
);
assert
(
head
<
capacity
);
assert
(
tail
<
size
);
assert
(
tail
<
capacity
);
assert
(
n
<
size
);
assert
(
n
<
capacity
);
assert
(
head
+
n
<=
size
);
assert
(
head
+
n
<=
capacity
);
assert
(
tail
<
head
||
head
+
n
<=
tail
);
assert
(
tail
<
head
||
head
+
n
<=
tail
);
head
+=
n
;
head
+=
n
;
if
(
head
==
size
)
if
(
head
==
capacity
)
head
=
0
;
head
=
0
;
}
}
};
};
...
...
test/TestCircularBuffer.hxx
View file @
3d4f588a
...
@@ -24,6 +24,8 @@ public:
...
@@ -24,6 +24,8 @@ public:
int
data
[
N
];
int
data
[
N
];
CircularBuffer
<
int
>
buffer
(
data
,
N
);
CircularBuffer
<
int
>
buffer
(
data
,
N
);
CPPUNIT_ASSERT_EQUAL
(
size_t
(
N
),
buffer
.
GetCapacity
());
/* '.' = empty; 'O' = occupied; 'X' = blocked */
/* '.' = empty; 'O' = occupied; 'X' = blocked */
/* checks on empty buffer */
/* checks on empty buffer */
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment