mirror of
https://github.com/aljazceru/crawler_v2.git
synced 2025-12-17 07:24:21 +01:00
moved buffer closer to its usage in Firehose
This commit is contained in:
@@ -203,3 +203,25 @@ func Firehose(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type buffer struct {
|
||||||
|
IDs []string
|
||||||
|
capacity int
|
||||||
|
write int
|
||||||
|
}
|
||||||
|
|
||||||
|
func newBuffer(capacity int) *buffer {
|
||||||
|
return &buffer{
|
||||||
|
IDs: make([]string, capacity),
|
||||||
|
capacity: capacity,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *buffer) Add(ID string) {
|
||||||
|
b.IDs[b.write] = ID
|
||||||
|
b.write = (b.write + 1) % b.capacity
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *buffer) Contains(ID string) bool {
|
||||||
|
return slices.Contains(b.IDs, ID)
|
||||||
|
}
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"slices"
|
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
"github.com/nbd-wtf/go-nostr"
|
"github.com/nbd-wtf/go-nostr"
|
||||||
@@ -73,25 +72,3 @@ func shutdown(pool *nostr.SimplePool) {
|
|||||||
return true
|
return true
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
type buffer struct {
|
|
||||||
IDs []string
|
|
||||||
capacity int
|
|
||||||
write int
|
|
||||||
}
|
|
||||||
|
|
||||||
func newBuffer(capacity int) *buffer {
|
|
||||||
return &buffer{
|
|
||||||
IDs: make([]string, capacity),
|
|
||||||
capacity: capacity,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (b *buffer) Add(ID string) {
|
|
||||||
b.IDs[b.write] = ID
|
|
||||||
b.write = (b.write + 1) % b.capacity
|
|
||||||
}
|
|
||||||
|
|
||||||
func (b *buffer) Contains(ID string) bool {
|
|
||||||
return slices.Contains(b.IDs, ID)
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user