diff options
| author | Guillaume Horel <guillaume.horel@gmail.com> | 2018-04-24 11:22:24 -0400 |
|---|---|---|
| committer | Guillaume Horel <guillaume.horel@gmail.com> | 2018-04-24 13:21:34 -0400 |
| commit | 81a39408e68c5b5e8bef599d122a0eb727e704af (patch) | |
| tree | ed4bed5ebbb197f4e174d6d396bde17dff0dec40 | |
| parent | fbe7cd5638e7520349f06f3fddeb6bc18d0d324f (diff) | |
| download | pyisda-81a39408e68c5b5e8bef599d122a0eb727e704af.tar.gz | |
fix hash
| -rw-r--r-- | pyisda/credit_index.pyx | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/pyisda/credit_index.pyx b/pyisda/credit_index.pyx index 44d345e..a809567 100644 --- a/pyisda/credit_index.pyx +++ b/pyisda/credit_index.pyx @@ -271,7 +271,7 @@ cdef class CreditIndex(CurveList): cdef: TCurve* curve = self._curves[0].get() size_t size = TCurve_size(curve.fNumItems) - size_t buf_size = size + sizeof(size_t) + curve.fNumItems * sizeof(double) + 8 + size_t buf_size = size + curve.fNumItems * sizeof(double) + 8 unsigned char* buf = <unsigned char*>malloc(buf_size) unsigned char* cursor unsigned char* start = buf + size @@ -283,18 +283,20 @@ cdef class CreditIndex(CurveList): cursor = start curve = self._curves[p.second].get() serialize(curve, buf) - p.first.copy(<char*>cursor, p.first.length(), 0) - #0 padding if p.first.length() < 8: + p.first.copy(<char*>cursor, p.first.length(), 0) + #0 padding memset(cursor + p.first.length(), 0, 8 - p.first.length()) + else: + p.first.copy(<char*>cursor, 8, 0) cursor += 8 memcpy(cursor, self.recovery_rates[p.second].get(), curve.fNumItems * sizeof(double)) h ^= Hash64(<char*>buf, buf_size) - free(buf) h = Hash64WithSeed(<char*>&self.start_date, sizeof(TDate), h) + h = Hash64WithSeed(<char*>&self.base_date, sizeof(TDate), h) h = Hash64WithSeed(<char*>self._maturities.data(), sizeof(TDate) * self._maturities.size(), h) - h = Hash64WithSeed(<char*>self._weights.data(), sizeof(double) * self._weights.size(), h) + h = Hash64WithSeed(<char*>self._weights.data(), sizeof(double) * self._weights.size(), h) return h #@cython.initializedcheck(False) |
