Adds a database.

This is a really simple map. Calls to it just check if the key exists
and return a bool. In case of a false it adds the key.
The key is just a string which might or might not be sufficient.
This commit is contained in:
Harm Aarts 2013-12-05 15:30:26 +01:00
parent bfbe2dd3be
commit 90c93b8fa4
1 changed files with 33 additions and 0 deletions

33
database.go Normal file
View File

@ -0,0 +1,33 @@
/*
Credits go to github.com/SlyMarbo/rss for inspiring this solution.
*/
package feeder
type database struct {
request chan string
response chan bool
known map[string]struct{}
}
func (d *database) Run() {
d.known = make(map[string]struct{})
var s string
for {
s = <-d.request
if _, ok := d.known[s]; ok {
d.response <- true
} else {
d.response <- false
d.known[s] = struct{}{}
}
}
}
func NewDatabase() *database {
database := new(database)
database.request = make(chan string)
database.response = make(chan bool)
go database.Run()
return database
}