pdqhash-go

git clone git://archive.git.mtrnord.blog/MTRNord/pdqhash-go.git
Log | Files | Refs | LICENSE

commit 1847691a456504321e2f0ad1761de8134eac1604
parent bb38219da9141413d874ac0b26bb82ca17881a52
Author: MTRNord <mtrnord1@gmail.com>
Date:   Sun, 25 Feb 2024 01:53:14 +0100

Minor code cleanup

Diffstat:
Mpdq_hasher.go | 18++++--------------
Mtypes/hash256.go | 17+++++------------
2 files changed, 9 insertions(+), 26 deletions(-)

diff --git a/pdq_hasher.go b/pdq_hasher.go @@ -180,8 +180,6 @@ func (p *PDQHasher) pdqHash256FromFloatLuma(fullBuffer1, fullBuffer2 []float64, } func (p *PDQHasher) dihedralFromFile(filename string, dihedralFlags int) HashesAndQuality { - vips.Startup(nil) - defer vips.Shutdown() image, err := vips.NewImageFromFile(filename) if err != nil { log.Fatalf("Error opening file: %v", err) @@ -489,46 +487,38 @@ func (p *PDQHasher) box1DFloat(invec *[]float64, inStartOffset int, outvec *[]fl currentWindowSize := 0 // PHASE 1: ACCUMULATE FIRST SUM NO WRITES - i := 0 - for i < phase_1_nreps { + for i := 0; i < phase_1_nreps; i++ { sum += (*invec)[inStartOffset+ri] currentWindowSize += 1 ri += stride - i += 1 } // PHASE 2: INITIAL WRITES WITH SMALL WINDOW - i = 0 - for i < phase_2_nreps { + for i := 0; i < phase_2_nreps; i++ { sum += (*invec)[inStartOffset+ri] currentWindowSize += 1 (*outvec)[outStartOffset+oi] = sum / float64(currentWindowSize) ri += stride oi += stride - i += 1 } // PHASE 3: WRITES WITH FULL WINDOW - i = 0 - for i < phase_3_nreps { + for i := 0; i < phase_3_nreps; i++ { sum += (*invec)[inStartOffset+ri] sum -= (*invec)[inStartOffset+li] (*outvec)[outStartOffset+oi] = sum / float64(currentWindowSize) li += stride ri += stride oi += stride - i += 1 } // PHASE 4: FINAL WRITES WITH SMALL WINDOW - i = 0 - for i < phase_4_nreps { + for i := 0; i < phase_4_nreps; i++ { sum -= (*invec)[inStartOffset+li] currentWindowSize -= 1 (*outvec)[outStartOffset+oi] = sum / float64(currentWindowSize) li += stride oi += stride - i += 1 } } diff --git a/types/hash256.go b/types/hash256.go @@ -28,12 +28,10 @@ func (h *Hash256) Clone() Hash256 { } func (h *Hash256) String() string { - i := HASH256_NUM_SLOTS - 1 var result []string - for i >= 0 { + for i := HASH256_NUM_SLOTS - 1; i >= 0; i-- { result = append(result, fmt.Sprintf("%04x", h.W[i]&0xFFFF)) - i = i - 1 } return strings.Join(result, "") @@ -88,10 +86,9 @@ func (h *Hash256) SetAll() { func (h *Hash256) HammingNorm() int { n := 0 - i := 0 - for i < HASH256_NUM_SLOTS { + + for i := 0; i < HASH256_NUM_SLOTS; i++ { n += h.HammingNorm16(h.W[i]) - i += 1 } return n } @@ -158,8 +155,7 @@ func (h *Hash256) BitwiseNOT() Hash256 { func (h *Hash256) DumpBits() string { var str []string - i := HASH256_NUM_SLOTS - 1 - for i >= 0 { + for i := HASH256_NUM_SLOTS - 1; i >= 0; i-- { word := h.W[i] & 0xFFFF var bits []string for j := 15; j >= 0; j-- { @@ -170,7 +166,6 @@ func (h *Hash256) DumpBits() string { } } str = append(str, strings.Join(bits, " ")) - i-- } return strings.Join(str, "\n") } @@ -178,8 +173,7 @@ func (h *Hash256) DumpBits() string { func (h *Hash256) DumpBitsAcross() string { var str []string - i := HASH256_NUM_SLOTS - 1 - for i >= 0 { + for i := HASH256_NUM_SLOTS - 1; i >= 0; i-- { word := h.W[i] & 0xFFFF for j := 15; j >= 0; j-- { if (word & (1 << uint(j))) != 0 { @@ -188,7 +182,6 @@ func (h *Hash256) DumpBitsAcross() string { str = append(str, "0") } } - i-- } return strings.Join(str, " ") }