Go djb2 구현

Jmnote (토론 | 기여)님의 2024년 3월 3일 (일) 14:47 판 (새 문서: ==개요== ;Go djb2 구현 ;Go djb2 해시 테이블 구현 <syntaxhighlight lang='console'> package main import ( "fmt" ) func djb2(text string) uint64 { var hash uint64 = 5381...)
(차이) ← 이전 판 | 최신판 (차이) | 다음 판 → (차이)

1 개요

Go djb2 구현
Go djb2 해시 테이블 구현
package main

import (
	"fmt"
)

func djb2(text string) uint64 {
	var hash uint64 = 5381
	for i := 0; i < len(text); i++ {
		char := text[i]
		hash = ((hash << 5) + hash) + uint64(char)
	}
	return hash
}

func main() {
	fmt.Println(djb2("hello")) // 210714636441
	fmt.Println(djb2("world")) // 210732791149
}


2 같이 보기

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}