blob: 703140f4515ac8340d40bde25876f5fc6e7d19e3 [file] [log] [blame]
// Copyright 2016 The LUCI Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package main
import (
"fmt"
"os"
)
func main() {
f, err := os.Create("bf_table.gen.go")
if err != nil {
panic(err)
}
defer f.Close()
w := func(format string, a ...interface{}) {
_, err := fmt.Fprintf(f, format, a...)
if err != nil {
panic(err)
}
}
w("// Copyright 2016 The LUCI Authors. All rights reserved.\n")
w("// Use of this source code is governed under the Apache License, Version 2.0\n")
w("// that can be found in the LICENSE file.\n\n")
w("// AUTOGENERATED: DO NOT EDIT\n")
w("\npackage bitfield\n\n")
w("var bitCount = [256]byte{")
tbl := [256]int{}
for i := 0; i < 256; i++ {
if i%16 == 0 {
w("\n\t")
} else {
w(" ")
}
tbl[i] = (i & 1) + tbl[i/2]
w("%d,", tbl[i])
}
w("\n}\n")
}