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

Question about add node to Variable #83

Closed
woodliu opened this issue Apr 18, 2024 · 1 comment
Closed

Question about add node to Variable #83

woodliu opened this issue Apr 18, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@woodliu
Copy link

woodliu commented Apr 18, 2024

Before add a node to Variable, it needs to call findBucket to find a location for the node.

func (v *Variable[K, V]) findBucket(expiration uint32) node.Node[K, V] {
	duration := expiration - v.time
	length := len(v.wheel) - 1
	for i := 0; i < length; i++ {
		if duration < spans[i+1] {
			ticks := expiration >> shift[i]
			index := ticks & (buckets[i] - 1)
			return v.wheel[i][index]
		}
	}
	return v.wheel[length][0]
}

My question is why use ticks := expiration >> shift[i] (not ticks := duration >> shift[i]) to calculate the location in v.wheel[i] ?
I think use ticks := duration >> shift[i] is more reasonable, because it represent the distance(Or time difference) from the avaliable data location(v.time>> shift[i]). expiration is a random value(unixtime.Now()+ttl), it can be anywhere in v.wheel[i], conflict with the RemoveExpired.

@woodliu woodliu added the enhancement New feature or request label Apr 18, 2024
@woodliu
Copy link
Author

woodliu commented Apr 18, 2024

Sorry, if use ticks := duration >> shift[i], it needs to add the v.time too...

@woodliu woodliu closed this as completed Apr 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant