[squid-dev] [PATCH] implement std::hash<SBuf>

Amos Jeffries squid3 at treenet.co.nz
Mon Jul 27 23:02:37 UTC 2015


On 28/07/2015 5:44 a.m., Kinkie wrote:
> Hi,
>    the attached patch makes it possible to have a default hasher
> implementation for SBuf, thus enabling baseline std::unordered_map<SBuf,*>
> support.
> Different, more specialized, hash functions can be of course implemented
> via template arguments to std::unordered_map of course.
> The implementation is a reworked hash_string, so it shouldn't be any less
> effective than that for our workloads.


in src/SBuf.cc:

* you have the comment "ripped from hash_string".
- Please state clearly what STL implementation you 'ripped' it from, and
what copyright license that source uses. It does vary by OS and we
cannot copy from some of them.
 - If its not explicitly public, GPLv2+ (*not* v2 or v3), or BSD
2-/3-clause please go find a BSD library implementation instead :-)

* document that magic constant '271'.
 - Even if its just a note that the copied source used it for unknown
reasons.


in src/SBuf.h:

* does the functor have to be defined inside std:: ?
- my understanding was that namespace was reserved for STL use, and that
a global-scoped definition should be found okay by the compiler.

* please dont remove the empty line at the end of file.
 - it will just be added back by source-maintenance after merge.


in src/tests/testSBuf.cc:

* please add a test for over/under reads by the hasher.
 - this should be able to catch it whereas the other tests might not:

   hasher(SBuf("AfoxA").substr(1,3)) == \
   hasher(SBuf("BfoxB").substr(1,3))


Amos



More information about the squid-dev mailing list