From 1a8633f3a5eaafb03b2b5e384c7e70e04fec57d8 Mon Sep 17 00:00:00 2001 From: Seebs Date: Tue, 13 Nov 2018 13:33:52 -0600 Subject: [PATCH] use roaring conventions for variable names Roaring likes to call things "a" and "b", not "1" and "2", and use "n" for length, not "l", etcetera. Adopt these conventions to make code more readable. Also drop the 'vb' value since it isn't expensive to compute and the compiler can figure out that it can reuse the value. --- roaring/roaring.go | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/roaring/roaring.go b/roaring/roaring.go index 6cf7eda1c..bb3c5da6e 100644 --- a/roaring/roaring.go +++ b/roaring/roaring.go @@ -1903,25 +1903,24 @@ func intersectionCount(a, b *Container) int32 { func intersectionCountArrayArray(a, b *Container) (n int32) { statsHit("intersectionCount/ArrayArray") - s1, s2 := a.array, b.array - if len(s1) == 0 || len(s2) == 0 { + ca, cb := a.array, b.array + na, nb := len(ca), len(cb) + if na == 0 || nb == 0 { return 0 } - if len(s1) > len(s2) { - s1, s2 = s2, s1 + if na > nb { + ca, cb = cb, ca + na, nb = nb, na } - l2 := len(s2) - i2 := 0 - v2 := s2[0] - for _, v1 := range s1 { - for v2 < v1 { - i2++ - if i2 >= l2 { + j := 0 + for _, va := range ca { + for cb[j] < va { + j++ + if j >= nb { return n } - v2 = s2[i2] } - if v2 == v1 { + if cb[j] == va { n++ } }