Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
Yu Zhao committed May 28, 2018
1 parent 9ed559d commit e1a29d5
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions ch12/ex01.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package main

import (
"fmt"
"math/rand"
"log"
)

type Eight9Hash struct{
size int
arr [1E8]bool
}

func main() {
eh := new(Eight9Hash)
fmt.Println(eh.getNumber())
// fmt.Println(eh.getNumber())
// fmt.Println(eh.getNumber())
// fmt.Println(eh.getNumber())
fmt.Println(eh.requestNumber(19727887))
}

func (eh *Eight9Hash) getNumber() int {
r := rand.Intn(1E8)
limit := r - 1;
if limit == -1 {
limit = 99999999
}
for ; r != limit; {
if !eh.arr[r] {
eh.arr[r] = true
return r
} else {
r ++
if r == 1E8 {
r = 0
}
}
}
log.Fatal("error: Full Hash set")
return 0
}


func (eh *Eight9Hash) requestNumber(n int) bool {
return eh.arr[n]
}

0 comments on commit e1a29d5

Please sign in to comment.