Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

runtime: interface hash table not Quadratic Probing #41553

dreamerjackson opened this issue Sep 22, 2020 · 2 comments

runtime: interface hash table not Quadratic Probing #41553

dreamerjackson opened this issue Sep 22, 2020 · 2 comments


Copy link

@dreamerjackson dreamerjackson commented Sep 22, 2020

i read soource code about interface hash table. the code say hash use Quadratic Probing. but absolutely not.
this is just h +=i not h +=i *i, this is a special design or a bug?

func (t *itabTableType) find(inter *interfacetype, typ *_type) *itab {
	// Implemented using quadratic probing.
	// Probe sequence is h(i) = h0 + i*(i+1)/2 mod 2^k.
	// We're guaranteed to hit all table entries using this probe sequence.
	mask := t.size - 1
	h := itabHashFunc(inter, typ) & mask
	for i := uintptr(1); ; i++ {
		p := (**itab)(add(unsafe.Pointer(&t.entries), h*sys.PtrSize))
		// Use atomic read here so if we see m != nil, we also see
		// the initializations of the fields of m.
		// m := *p
		m := (*itab)(atomic.Loadp(unsafe.Pointer(p)))
		if m == nil {
			return nil
		if m.inter == inter && m._type == typ {
			return m
		h += i
		h &= mask
Copy link

@martisch martisch commented Sep 22, 2020

h is increased on every iteration by an i that is increasing on every iteration. If it would be linear if the addition would be by a costant e.g. h += 10.


Which gives the sum of integers 1+2+...+n = n*(n+1)/2

@martisch martisch closed this Sep 22, 2020
Copy link

@dreamerjackson dreamerjackson commented Oct 15, 2020


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.