typedef std::unordered_map<const buffer_handle_t, uint64_t,
BufferHasher, BufferComparator> BufferIdMap;
// 四个参数:key,value,hash生成器,大小比较器
生成器和 比较器中,重载了() --函数调用
486 struct BufferHasher {
487 size_t operator()(const buffer_handle_t& buf) const {
488 if (buf == nullptr)
489 return 0;
490
491 size_t result = 1;
492 result = 31 * result + buf->numFds;
493 result = 31 * result + buf->numInts;
494 int length = buf->numFds + buf->numInts;
495 for (int i = 0; i < length; i++) {
496 result = 31 * result + buf->data[i];
497 }
498 return result;
499 }
500 };
501
502 struct BufferComparator {
503 bool operator()(const buffer_handle_t& buf1, const buffer_handle_t& buf2) const {
504 if (buf1->numFds == buf2->numFds && buf1->numInts == buf2->numInts) {
505 int length = buf1->numFds + buf1->numInts;
506 for (int i = 0; i < length; i++) {
507 if (buf1->data[i] != buf2->data[i]) {
508 return false;
509 }
510 }
511 return true;
512 }
513 return false;
514 }
515 };