⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 merkle_hash.h

📁 chord 源码 http://pdos.csail.mit.edu/chord/
💻 H
字号:
#ifndef _MERKLE_HASH_H_#define _MERKLE_HASH_H_#include "async.h"#include "sha1.h"#include "itree.h"#include "sfsmisc.h"#include "crypt.h"#include "sha1.h"#undef setbitclass merkle_hash {private:  unsigned int getbit (unsigned int i) const;  void setbit (unsigned int i, bool on);public:  enum {  size = sha1::hashsize };  enum {  NUM_SLOTS = 27 };  u_int8_t bytes[size];  // XXX see template<class T> class zeroed_tmp_buf   // in sfs1/crypt/wmstr.h  // operator T *() const { return base; }  merkle_hash (unsigned int i = 0);  void randomize ();  u_int read_slot (u_int slotno) const;  void write_slot (u_int slotno, u_int val);  void clear_slot (int slotno);  void clear_suffix (int slotno);  int cmp (const merkle_hash &b) const;  hash_t to_hash () const;};inline const strbuf &strbuf_cat (const strbuf &sb, const merkle_hash &a){#if 1  for (u_int i = 0; i < merkle_hash::NUM_SLOTS; i++)    sb.fmt ("%2d ", a.read_slot (i));#else      for (int i = a.size - 1; i >= 0; i--)    sb.fmt ("%02x", a.bytes[i]);#endif  return sb;}bool func_xdr_merkle_hash (register XDR *, merkle_hash *);inline boolrpc_traverse (XDR *xdrs, merkle_hash &obj){  return func_xdr_merkle_hash (xdrs, &obj);}inline boolrpc_traverse (const stompcast_t, merkle_hash &obj){  return true;}#define xdr_merkle_hash reinterpret_cast<xdrproc_t> (func_xdr_merkle_hash) // XXXRPC_TYPE2STR_DECL (merkle_hash)inline RPC_PRINT_GEN (merkle_hash, sb << obj)inline boolxdr_putmerkle_hash (XDR *xdrs, const merkle_hash &obj){  assert (xdrs->x_op == XDR_ENCODE);  return func_xdr_merkle_hash (xdrs, const_cast<merkle_hash *> (&obj));}inline boolxdr_getmerkle_hash (XDR *xdrs, merkle_hash &obj){  assert (xdrs->x_op == XDR_DECODE);  return func_xdr_merkle_hash (xdrs, const_cast<merkle_hash *> (&obj));}#undef CMPOPX#define CMPOPX(X)						\inline bool							\operator X (const merkle_hash &a, const merkle_hash &b)	        \{								\  return a.cmp (b) X 0;                                         \}								\CMPOPX (<)CMPOPX (>)CMPOPX (<=)CMPOPX (>=)CMPOPX (==)CMPOPX (!=)static inline boolprefix_match (int nslots, const merkle_hash &a, const merkle_hash &b){  for (int i = 0; i < nslots; i++)    if (a.read_slot (i) != b.read_slot (i))      return false;  return true;}template <>struct hashfn<merkle_hash> {  hashfn () {}  hash_t operator() (const merkle_hash &a) const  {    return a.to_hash ();  }};#endif /* _MERKLE_HASH_H_ */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -