26 # include "rabinkarp.h"
59 static inline void weaksum_reset(
weaksum_t *sum)
61 if (sum->kind == RS_ROLLSUM)
62 RollsumInit(&sum->sum.rs);
64 rabinkarp_init(&sum->sum.rk);
67 static inline void weaksum_init(
weaksum_t *sum, weaksum_kind_t kind)
69 assert(kind == RS_ROLLSUM || kind == RS_RABINKARP);
74 static inline size_t weaksum_count(
weaksum_t *sum)
77 return sum->sum.rs.count;
80 static inline void weaksum_update(
weaksum_t *sum,
const unsigned char *buf,
83 if (sum->kind == RS_ROLLSUM)
84 RollsumUpdate(&sum->sum.rs, buf, len);
86 rabinkarp_update(&sum->sum.rk, buf, len);
89 static inline void weaksum_rotate(
weaksum_t *sum,
unsigned char out,
92 if (sum->kind == RS_ROLLSUM)
93 RollsumRotate(&sum->sum.rs, out, in);
95 rabinkarp_rotate(&sum->sum.rk, out, in);
98 static inline void weaksum_rollin(
weaksum_t *sum,
unsigned char in)
100 if (sum->kind == RS_ROLLSUM)
101 RollsumRollin(&sum->sum.rs, in);
103 rabinkarp_rollin(&sum->sum.rk, in);
106 static inline void weaksum_rollout(
weaksum_t *sum,
unsigned char out)
108 if (sum->kind == RS_ROLLSUM)
109 RollsumRollout(&sum->sum.rs, out);
111 rabinkarp_rollout(&sum->sum.rk, out);
114 static inline rs_weak_sum_t weaksum_digest(
weaksum_t *sum)
116 if (sum->kind == RS_ROLLSUM)
118 return mix32(RollsumDigest(&sum->sum.rs));
120 return rabinkarp_digest(&sum->sum.rk);
129 rs_weak_sum_t rs_calc_weak_sum(weaksum_kind_t kind,
void const *buf,
133 void rs_calc_strong_sum(strongsum_kind_t kind,
void const *buf,
size_t len,
134 rs_strong_sum_t *sum);