+}
+
+size_t IOBuf::fillIov(struct iovec* iov, size_t len) const {
+ IOBuf const* p = this;
+ size_t i = 0;
+ while (i < len) {
+ // some code can get confused by empty iovs, so skip them
+ if (p->length() > 0) {
+ iov[i].iov_base = const_cast<uint8_t*>(p->data());
+ iov[i].iov_len = p->length();
+ i++;
+ }
+ p = p->next();
+ if (p == this) {
+ return i;
+ }
+ }
+ return 0;
+}
+
+size_t IOBufHash::operator()(const IOBuf& buf) const {
+ folly::hash::SpookyHashV2 hasher;
+ hasher.Init(0, 0);
+ io::Cursor cursor(&buf);
+ for (;;) {
+ auto b = cursor.peekBytes();
+ if (b.empty()) {
+ break;
+ }
+ hasher.Update(b.data(), b.size());
+ cursor.skip(b.size());
+ }
+ uint64_t h1;
+ uint64_t h2;
+ hasher.Final(&h1, &h2);
+ return h1;
+}
+
+bool IOBufEqual::operator()(const IOBuf& a, const IOBuf& b) const {
+ io::Cursor ca(&a);
+ io::Cursor cb(&b);
+ for (;;) {
+ auto ba = ca.peekBytes();
+ auto bb = cb.peekBytes();
+ if (ba.empty() && bb.empty()) {
+ return true;
+ } else if (ba.empty() || bb.empty()) {
+ return false;
+ }
+ size_t n = std::min(ba.size(), bb.size());
+ DCHECK_GT(n, 0u);
+ if (memcmp(ba.data(), bb.data(), n)) {
+ return false;
+ }
+ ca.skip(n);
+ cb.skip(n);
+ }