Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
dlib
Commits
2f60267e
Commit
2f60267e
authored
Jan 31, 2015
by
Davis King
Browse files
Added batch ingest functions for std::vector<char>
parent
2d94fc95
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
58 additions
and
0 deletions
+58
-0
dlib/crc32/crc32_kernel_1.h
dlib/crc32/crc32_kernel_1.h
+32
-0
dlib/crc32/crc32_kernel_abstract.h
dlib/crc32/crc32_kernel_abstract.h
+21
-0
dlib/test/crc32.cpp
dlib/test/crc32.cpp
+5
-0
No files found.
dlib/crc32/crc32_kernel_1.h
View file @
2f60267e
...
@@ -5,6 +5,7 @@
...
@@ -5,6 +5,7 @@
#include "../algs.h"
#include "../algs.h"
#include <string>
#include <string>
#include <vector>
#include "crc32_kernel_abstract.h"
#include "crc32_kernel_abstract.h"
namespace
dlib
namespace
dlib
...
@@ -34,6 +35,10 @@ namespace dlib
...
@@ -34,6 +35,10 @@ namespace dlib
const
std
::
string
&
item
const
std
::
string
&
item
);
);
inline
crc32
(
const
std
::
vector
<
char
>&
item
);
inline
virtual
~
crc32
(
inline
virtual
~
crc32
(
);
);
...
@@ -48,6 +53,10 @@ namespace dlib
...
@@ -48,6 +53,10 @@ namespace dlib
const
std
::
string
&
item
const
std
::
string
&
item
);
);
inline
void
add
(
const
std
::
vector
<
char
>&
item
);
inline
unsigned
long
get_checksum
(
inline
unsigned
long
get_checksum
(
)
const
;
)
const
;
...
@@ -124,6 +133,18 @@ namespace dlib
...
@@ -124,6 +133,18 @@ namespace dlib
add
(
item
);
add
(
item
);
}
}
// ----------------------------------------------------------------------------------------
crc32
::
crc32
(
const
std
::
vector
<
char
>&
item
)
{
checksum
=
0xFFFFFFFF
;
fill_crc_table
();
add
(
item
);
}
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
crc32
::
crc32
::
...
@@ -162,6 +183,17 @@ namespace dlib
...
@@ -162,6 +183,17 @@ namespace dlib
checksum
=
(
checksum
>>
8
)
^
table
[(
checksum
^
item
[
i
])
&
0xFF
];
checksum
=
(
checksum
>>
8
)
^
table
[(
checksum
^
item
[
i
])
&
0xFF
];
}
}
// ----------------------------------------------------------------------------------------
void
crc32
::
add
(
const
std
::
vector
<
char
>&
item
)
{
for
(
unsigned
long
i
=
0
;
i
<
item
.
size
();
++
i
)
checksum
=
(
checksum
>>
8
)
^
table
[(
checksum
^
item
[
i
])
&
0xFF
];
}
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
unsigned
long
crc32
::
unsigned
long
crc32
::
...
...
dlib/crc32/crc32_kernel_abstract.h
View file @
2f60267e
...
@@ -5,6 +5,7 @@
...
@@ -5,6 +5,7 @@
#include "../algs.h"
#include "../algs.h"
#include <string>
#include <string>
#include <vector>
namespace
dlib
namespace
dlib
{
{
...
@@ -41,6 +42,17 @@ namespace dlib
...
@@ -41,6 +42,17 @@ namespace dlib
constructor and then calling add() on item)
constructor and then calling add() on item)
!*/
!*/
crc32
(
const
std
::
vector
<
char
>&
item
);
/*!
ensures
- #*this is properly initialized
- calls this->add(item).
(i.e. Using this constructor is the same as using the default
constructor and then calling add() on item)
!*/
virtual
~
crc32
(
virtual
~
crc32
(
);
);
/*!
/*!
...
@@ -73,6 +85,15 @@ namespace dlib
...
@@ -73,6 +85,15 @@ namespace dlib
concatenated with item.
concatenated with item.
!*/
!*/
void
add
(
const
std
::
vector
<
char
>&
item
);
/*!
ensures
- #get_checksum() == The checksum of all items added to *this previously
concatenated with item.
!*/
unsigned
long
get_checksum
(
unsigned
long
get_checksum
(
)
const
;
)
const
;
/*!
/*!
...
...
dlib/test/crc32.cpp
View file @
2f60267e
...
@@ -61,6 +61,11 @@ namespace
...
@@ -61,6 +61,11 @@ namespace
DLIB_TEST
(
c
.
get_checksum
()
==
0
);
DLIB_TEST
(
c
.
get_checksum
()
==
0
);
c
.
add
(
"davis"
);
c
.
add
(
"davis"
);
DLIB_TEST
(
c
.
get_checksum
()
==
0x0445527C
);
DLIB_TEST
(
c
.
get_checksum
()
==
0x0445527C
);
std
::
vector
<
char
>
buf
;
for
(
int
i
=
0
;
i
<
4000
;
++
i
)
buf
.
push_back
(
i
);
DLIB_TEST
(
crc32
(
buf
).
get_checksum
()
==
492662731
);
}
}
}
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