package main import ( "gomod.cblgh.org/iroh-tracker/stack" "fmt" ) const MAX_TOPICS = 5 const MAX_PEERS = 4 var topicToPeers map[string]*stack.Stack var topics *stack.Stack func main() { topics = stack.NewStack(MAX_TOPICS) topicToPeers = make(map[string]*stack.Stack) fmt.Println("topics to peers", topicToPeers) fmt.Println("topics slice", topics) visit("hello.topic", "alex") visit("nice.topic", "alex") visit("good.topic", "alex") visit("newer.topic", "alex") visit("great.topic", "alex") visit("newest.topic", "alex") // should evict hello.topic visit("newest.topic", "alex1") visit("newest.topic", "alex2") visit("newest.topic", "alex3") visit("newest.topic", "alex4") fmt.Printf("%+v\n", topicToPeers) fmt.Printf("%+v\n", topicToPeers["newest.topic"]) } func visit(topic, peer string) { peers, exists := topicToPeers[topic] if !exists { peers = stack.NewStack(MAX_PEERS) topicToPeers[topic] = peers fmt.Println("topic does not exist") } evicted := topics.Push(topic) peers.Push(peer) // forget about the old topic if evicted != "" { delete(topicToPeers, evicted) } }