Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
D
dlib
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
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
钟尚武
dlib
Commits
eeeee7ff
Commit
eeeee7ff
authored
Mar 07, 2012
by
Davis King
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added unit tests for the circular_buffer and fixed a few things.
parent
cd100541
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
141 additions
and
6 deletions
+141
-6
circular_buffer.h
dlib/sliding_buffer/circular_buffer.h
+21
-2
circular_buffer_abstract.h
dlib/sliding_buffer/circular_buffer_abstract.h
+11
-4
sliding_buffer.cpp
dlib/test/sliding_buffer.cpp
+109
-0
No files found.
dlib/sliding_buffer/circular_buffer.h
View file @
eeeee7ff
...
@@ -59,8 +59,20 @@ namespace dlib
...
@@ -59,8 +59,20 @@ namespace dlib
return
data
[(
i
+
offset
)
%
data
.
size
()];
return
data
[(
i
+
offset
)
%
data
.
size
()];
}
}
void
resize
(
unsigned
long
size
,
const
T
&
value
=
T
())
{
data
.
resize
(
size
,
value
);
}
void
resize
(
unsigned
long
size
)
void
assign
(
unsigned
long
size
,
const
T
&
value
)
{
data
.
assign
(
size
,
value
);
}
{
offset
=
0
;
data
.
resize
(
size
);
}
void
assign
(
unsigned
long
size
,
const
T
&
value
)
{
offset
=
0
;
data
.
assign
(
size
,
value
);
}
unsigned
long
size
()
const
{
return
data
.
size
();
}
unsigned
long
size
()
const
{
return
data
.
size
();
}
...
@@ -126,6 +138,13 @@ namespace dlib
...
@@ -126,6 +138,13 @@ namespace dlib
return
(
*
this
)[
size
()
-
1
];
return
(
*
this
)[
size
()
-
1
];
}
}
void
swap
(
circular_buffer
&
item
)
{
std
::
swap
(
item
.
offset
,
offset
);
data
.
swap
(
item
.
data
);
}
private
:
private
:
std
::
vector
<
T
>
data
;
std
::
vector
<
T
>
data
;
...
...
dlib/sliding_buffer/circular_buffer_abstract.h
View file @
eeeee7ff
...
@@ -78,15 +78,22 @@ namespace dlib
...
@@ -78,15 +78,22 @@ namespace dlib
!*/
!*/
void
resize
(
void
resize
(
unsigned
long
new_size
);
/*!
ensures
- #size() == new_size
!*/
void
assign
(
unsigned
long
new_size
,
unsigned
long
new_size
,
const
T
&
c
=
T
()
const
T
&
value
);
);
/*!
/*!
ensures
ensures
- #size() == new_size
- #size() == new_size
- any element with index between 0 and new_size - 1 which was in the
- for all valid i:
circular_buffer before the call to resize() retains its value and index.
- (*this)[i] == value
All other elements have a value given by c.
!*/
!*/
unsigned
long
size
(
unsigned
long
size
(
...
...
dlib/test/sliding_buffer.cpp
View file @
eeeee7ff
...
@@ -304,6 +304,113 @@ namespace
...
@@ -304,6 +304,113 @@ namespace
void
test_circular_buffer
()
{
circular_buffer
<
int
>
buf
;
DLIB_TEST
(
buf
.
size
()
==
0
);
buf
.
assign
(
4
,
0
);
DLIB_TEST
(
buf
.
size
()
==
4
);
DLIB_TEST
(
buf
[
0
]
==
0
);
DLIB_TEST
(
buf
[
1
]
==
0
);
DLIB_TEST
(
buf
[
2
]
==
0
);
DLIB_TEST
(
buf
[
3
]
==
0
);
buf
.
push_back
(
1
);
DLIB_TEST
(
buf
[
0
]
==
0
);
DLIB_TEST
(
buf
[
1
]
==
0
);
DLIB_TEST
(
buf
[
2
]
==
0
);
DLIB_TEST
(
buf
[
3
]
==
1
);
buf
.
push_back
(
2
);
DLIB_TEST
(
buf
[
0
]
==
0
);
DLIB_TEST
(
buf
[
1
]
==
0
);
DLIB_TEST
(
buf
[
2
]
==
1
);
DLIB_TEST
(
buf
[
3
]
==
2
);
buf
.
push_front
(
3
);
DLIB_TEST
(
buf
[
0
]
==
3
);
DLIB_TEST
(
buf
[
1
]
==
0
);
DLIB_TEST
(
buf
[
2
]
==
0
);
DLIB_TEST
(
buf
[
3
]
==
1
);
buf
.
push_front
(
4
);
DLIB_TEST
(
buf
.
front
()
==
4
);
DLIB_TEST
(
buf
[
0
]
==
4
);
DLIB_TEST
(
buf
[
1
]
==
3
);
DLIB_TEST
(
buf
[
2
]
==
0
);
DLIB_TEST
(
buf
[
3
]
==
0
);
buf
.
assign
(
4
,
5
);
DLIB_TEST
(
buf
[
0
]
==
5
);
DLIB_TEST
(
buf
[
1
]
==
5
);
DLIB_TEST
(
buf
[
2
]
==
5
);
DLIB_TEST
(
buf
[
3
]
==
5
);
buf
.
push_back
(
3
);
DLIB_TEST
(
buf
[
0
]
==
5
);
DLIB_TEST
(
buf
[
1
]
==
5
);
DLIB_TEST
(
buf
[
2
]
==
5
);
DLIB_TEST
(
buf
[
3
]
==
3
);
buf
.
push_back
(
2
);
DLIB_TEST
(
buf
[
0
]
==
5
);
DLIB_TEST
(
buf
[
1
]
==
5
);
DLIB_TEST
(
buf
[
2
]
==
3
);
DLIB_TEST
(
buf
[
3
]
==
2
);
buf
.
push_back
(
1
);
DLIB_TEST
(
buf
[
0
]
==
5
);
DLIB_TEST
(
buf
[
1
]
==
3
);
DLIB_TEST
(
buf
[
2
]
==
2
);
DLIB_TEST
(
buf
[
3
]
==
1
);
buf
.
push_back
(
0
);
DLIB_TEST
(
buf
[
0
]
==
3
);
DLIB_TEST
(
buf
[
1
]
==
2
);
DLIB_TEST
(
buf
[
2
]
==
1
);
DLIB_TEST
(
buf
[
3
]
==
0
);
buf
.
push_back
(
-
1
);
DLIB_TEST
(
buf
.
back
()
==
-
1
);
DLIB_TEST
(
buf
[
0
]
==
2
);
DLIB_TEST
(
buf
[
1
]
==
1
);
DLIB_TEST
(
buf
[
2
]
==
0
);
DLIB_TEST
(
buf
[
3
]
==
-
1
);
buf
.
resize
(
1
);
buf
[
0
]
=
9
;
DLIB_TEST
(
buf
.
size
()
==
1
);
DLIB_TEST
(
buf
[
0
]
==
9
);
buf
.
push_back
(
1
);
DLIB_TEST
(
buf
[
0
]
==
1
);
buf
.
push_back
(
4
);
DLIB_TEST
(
buf
[
0
]
==
4
);
buf
.
push_front
(
3
);
DLIB_TEST
(
buf
[
0
]
==
3
);
buf
.
clear
();
DLIB_TEST
(
buf
.
size
()
==
0
);
buf
.
assign
(
3
,
0
);
circular_buffer
<
int
>
buf2
,
buf3
;
buf
.
push_back
(
1
);
buf
.
push_back
(
2
);
ostringstream
sout
;
serialize
(
buf
,
sout
);
istringstream
sin
(
sout
.
str
());
deserialize
(
buf2
,
sin
);
DLIB_TEST
(
buf
.
size
()
==
buf2
.
size
());
for
(
unsigned
long
i
=
0
;
i
<
buf
.
size
();
++
i
)
DLIB_TEST
(
buf
[
i
]
==
buf2
[
i
]);
buf
.
swap
(
buf3
);
DLIB_TEST
(
buf
.
size
()
==
0
);
DLIB_TEST
(
buf3
.
size
()
==
buf2
.
size
());
for
(
unsigned
long
i
=
0
;
i
<
buf3
.
size
();
++
i
)
DLIB_TEST
(
buf3
[
i
]
==
buf2
[
i
]);
}
...
@@ -323,6 +430,8 @@ namespace
...
@@ -323,6 +430,8 @@ namespace
sliding_buffer_kernel_test
<
sliding_buffer
<
unsigned
char
>::
kernel_1a
>
();
sliding_buffer_kernel_test
<
sliding_buffer
<
unsigned
char
>::
kernel_1a
>
();
dlog
<<
LINFO
<<
"testing kernel_1a_c"
;
dlog
<<
LINFO
<<
"testing kernel_1a_c"
;
sliding_buffer_kernel_test
<
sliding_buffer
<
unsigned
char
>::
kernel_1a_c
>
();
sliding_buffer_kernel_test
<
sliding_buffer
<
unsigned
char
>::
kernel_1a_c
>
();
test_circular_buffer
();
}
}
}
a
;
}
a
;
...
...
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