Просмотр исходного кода

changed []byte to string after finding out string indexing is faster than []byte in Go, since we're never modifying our string and only working with the accumulator we should see an improvement in speed in general

master
William Dillon 3 лет назад
Родитель
Сommit
cb20cac2f1
1 измененных файлов: 3 добавлений и 3 удалений
  1. 3
    3
      mishmash.go

+ 3
- 3
mishmash.go Просмотреть файл

@@ -38,7 +38,7 @@ func slct(n uint64) uint32 {
return primes[n&0xff]
}

func Engine(buffer []byte, length int, accumulator uint64) uint64 {
func Engine(buffer string, length int, accumulator uint64) uint64 {
for i := 0; i < length; i++ {
b := buffer[i]
accumulator += uint64(slct(accumulator)) + uint64(b)
@@ -48,7 +48,7 @@ func Engine(buffer []byte, length int, accumulator uint64) uint64 {
return accumulator
}

func Mishmash(buffer []byte, nums ...uint64) uint32 {
func Mishmash(buffer string, nums ...uint64) uint32 {
// nums is a seed/accumulator
var accumulator uint64
if 0 == len(nums) {
@@ -88,7 +88,7 @@ func main() {
// example below used to validate output against C++ mishmash
/*
func main() {
buf := []byte("Hello world!")
buf := "Hello world!"
first := MishmashAccumulator(Engine(buf, len(buf), 0))
second := MishmashAccumulator(Engine(buf, len(buf), 1))
var combo uint64

Загрузка…
Отмена
Сохранить