Commit 2f60267e authored by Davis King's avatar Davis King

Added batch ingest functions for std::vector<char>

parent 2d94fc95
......@@ -5,6 +5,7 @@
#include "../algs.h"
#include <string>
#include <vector>
#include "crc32_kernel_abstract.h"
namespace dlib
......@@ -34,6 +35,10 @@ namespace dlib
const std::string& item
);
inline crc32 (
const std::vector<char>& item
);
inline virtual ~crc32 (
);
......@@ -48,6 +53,10 @@ namespace dlib
const std::string& item
);
inline void add (
const std::vector<char>& item
);
inline unsigned long get_checksum (
) const;
......@@ -124,6 +133,18 @@ namespace dlib
add(item);
}
// ----------------------------------------------------------------------------------------
crc32::
crc32 (
const std::vector<char>& item
)
{
checksum = 0xFFFFFFFF;
fill_crc_table();
add(item);
}
// ----------------------------------------------------------------------------------------
crc32::
......@@ -162,6 +183,17 @@ namespace dlib
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::
......
......@@ -5,6 +5,7 @@
#include "../algs.h"
#include <string>
#include <vector>
namespace dlib
{
......@@ -41,6 +42,17 @@ namespace dlib
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 (
);
/*!
......@@ -73,6 +85,15 @@ namespace dlib
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 (
) const;
/*!
......
......@@ -61,6 +61,11 @@ namespace
DLIB_TEST(c.get_checksum() == 0);
c.add("davis");
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;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment