@@ -25,26 +25,29 @@ namespace dht {
2525namespace indexation {
2626
2727/* *
28- * Output the blob into string and readable way
28+ * Get bit string representation of a blob for a specified length.
2929 *
30- * @param bl : Blob to print
30+ * @param bl A Blob
31+ * @param len The number of bits to consider.
3132 *
32- * @return string that represent the blob into a readable way
33+ * @return string that represent the blob
3334 */
34- static std::string blobToString (const Blob &bl) {
35+ std::string Prefix::firstBitsToString (const Blob &bl, size_t len) const {
36+ if (len >= bl.size () * 8 )
37+ throw std::out_of_range (" specified length larger than blob size" );
3538 std::stringstream ss;
36- auto bn = bl.size () % 8 ;
37- auto n = bl.size () / 8 ;
39+ auto bn = len % 8 ;
3840
39- for (size_t i = 0 ; i < bl. size () ; i++)
40- ss << std::bitset<8 >(bl[i]) << " " ;
41+ for (size_t i = 0 ; i < len/ 8 ; i++)
42+ ss << std::bitset<8 >(bl[i]);
4143 if (bn)
42- for (unsigned b= 0 ; b < bn; b++)
43- ss << (char )((bl[n ] & (1 << (7 - b))) ? ' 1' :' 0' );
44+ for (unsigned b = 0 ; b < bn; b++)
45+ ss << (char )((bl[len/ 8 ] & (1 << (7 - b))) ? ' 1' :' 0' );
4446
4547 return ss.str ();
4648}
47- std::string Prefix::toString () const { return blobToString (content_); }
49+
50+ std::string Prefix::toString () const { return firstBitsToString (content_, size_); }
4851
4952void Pht::Cache::insert (const Prefix& p) {
5053 size_t i = 0 ;
0 commit comments