mirror of
https://github.com/golang/go.git
synced 2025-05-05 15:43:04 +00:00
go.tools/container/intsets: increase block size to 256 bits.
This consistently yields better performance with go/pointer. Also: return int not word from ntz(). LGTM=gri R=gri CC=golang-codereviews https://golang.org/cl/97570044
This commit is contained in:
parent
8df7a779db
commit
fd72015344
@ -21,6 +21,10 @@ package intsets
|
|||||||
// TODO(adonovan): implement Dense, a dense bit vector with a similar API.
|
// TODO(adonovan): implement Dense, a dense bit vector with a similar API.
|
||||||
// The space usage would be proportional to Max(), not Len(), and the
|
// The space usage would be proportional to Max(), not Len(), and the
|
||||||
// implementation would be based upon big.Int.
|
// implementation would be based upon big.Int.
|
||||||
|
//
|
||||||
|
// TODO(adonovan): experiment with making the root block indirect (nil
|
||||||
|
// iff IsEmpty). This would reduce the memory usage when empty and
|
||||||
|
// might simplify the aliasing invariants.
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
@ -50,7 +54,7 @@ type word uintptr
|
|||||||
const (
|
const (
|
||||||
_m = ^word(0)
|
_m = ^word(0)
|
||||||
bitsPerWord = 8 << (_m>>8&1 + _m>>16&1 + _m>>32&1)
|
bitsPerWord = 8 << (_m>>8&1 + _m>>16&1 + _m>>32&1)
|
||||||
bitsPerBlock = 128
|
bitsPerBlock = 256 // optimal value for go/pointer solver performance
|
||||||
wordsPerBlock = bitsPerBlock / bitsPerWord
|
wordsPerBlock = bitsPerBlock / bitsPerWord
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -161,9 +165,9 @@ func (b *block) min(take bool) int {
|
|||||||
if w != 0 {
|
if w != 0 {
|
||||||
tz := ntz(w)
|
tz := ntz(w)
|
||||||
if take {
|
if take {
|
||||||
b.bits[i] = w &^ (1 << tz)
|
b.bits[i] = w &^ (1 << uint(tz))
|
||||||
}
|
}
|
||||||
return b.offset + int(i*bitsPerWord) + int(tz)
|
return b.offset + int(i*bitsPerWord) + tz
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
panic("BUG: empty block")
|
panic("BUG: empty block")
|
||||||
|
@ -44,11 +44,11 @@ func nlz(x word) int {
|
|||||||
|
|
||||||
// ntz returns the number of trailing zeros of x.
|
// ntz returns the number of trailing zeros of x.
|
||||||
// From Hacker's Delight, fig 5.13.
|
// From Hacker's Delight, fig 5.13.
|
||||||
func ntz(x word) word {
|
func ntz(x word) int {
|
||||||
if x == 0 {
|
if x == 0 {
|
||||||
return bitsPerWord
|
return bitsPerWord
|
||||||
}
|
}
|
||||||
var n word = 1
|
n := 1
|
||||||
if bitsPerWord == 64 {
|
if bitsPerWord == 64 {
|
||||||
if (x & 0xffffffff) == 0 {
|
if (x & 0xffffffff) == 0 {
|
||||||
n = n + 32
|
n = n + 32
|
||||||
@ -71,5 +71,5 @@ func ntz(x word) word {
|
|||||||
n = n + 2
|
n = n + 2
|
||||||
x = x >> 2
|
x = x >> 2
|
||||||
}
|
}
|
||||||
return n - x&1
|
return n - int(x&1)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user