Code Monkey home page Code Monkey logo

lc's People

Contributors

simplejia avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

lc's Issues

integer divide by zero

lc.Init(50)
如果数量小于100的话,Get的时候会报错

panic: runtime error: integer divide by zero
github.com/simplejia/lc/hashmap.go:35 +0x1a8

github.com/simplejia/lc/hashmap.go

func (this *HashMap) Init(num int) *HashMap {
	if this == nil {
		this = new(HashMap)
	}
	this.blen = 100
	capacity := num / this.blen * this.blen
	this.bnum = capacity / this.blen
	this.elems = make([]*Elem, capacity, capacity)

	return this
}

这里this.blen = 100导致capacity和bnum等于0了?

过期后仍返回true

func main() {
	lcKey := "k"
	lcValue := "v"

	lc.Set(lcKey, lcValue, time.Second*3)

	ticker := time.NewTicker(time.Second)
	defer ticker.Stop()

	go func() {
		for range ticker.C {
			v, ok := lc.Get(lcKey)
			fmt.Println(v, ok)
		}
	}()

	time.Sleep(time.Second*6)
}

这里设置了一个3秒过期的key,每间隔1s去get一次,输入如下:

v true
v true
v false
v true
v true

第三秒时返回false,说明正常过期,3秒后返回true?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.