<commit_before>package router

import (
	"container/list"
	"errors"
	"log"
	"sync"
)

type Channel struct {
	sync.RWMutex
	channel chan interface{}
	closed  bool
}

func NewChannel(depth int) *Channel {
	return &Channel{
		sync.RWMutex{},
		make(chan interface{}, depth),
		false,
	}
}

func (t *Channel) Enqueue(data interface{}) error {
	t.RLock()
	defer t.RUnlock()
	if t.closed {
		return errors.New("channel closed")
	}
	t.channel <- data
	return nil
}

func (t *Channel) Dequeue() <-chan interface{} {
	return t.channel
}

func (t *Channel) Close() {
	t.Lock()
	defer t.Unlock()
	t.closed = true
	close(t.channel)
}

type RouteList struct {
	*sync.RWMutex
	*list.List
}

type RouteMap map[string]RouteList

var lock = sync.RWMutex{}
var routes = make(RouteMap)

func AddChannel(path string, channel ...*Channel) error {
	lock.Lock()
	defer lock.Unlock()

	log.Printf("Adding channel for path [%s]\n", path)

	if _, ok := routes[path]; !ok {
		routes[path] = RouteList{
			&sync.RWMutex{},
			list.New(),
		}
	}

	routes[path].Lock()
	defer routes[path].Unlock()
	for _, c := range channel {
		routes[path].PushBack(c)
	}

	log.Println("Routes", len(routes))
	for _, v := range routes {
		log.Println(v.Len())
	}

	return nil
}

func CloseChannel(path string, channel *Channel) {
	lock.Lock()
	defer lock.Unlock()<commit_msg>updating router<commit_after>package router

import (
	"container/list"
	"errors"
	"log"
	"sync"
)

type Channel struct {
	sync.RWMutex
	channel chan interface{}
	closed  bool
}

func NewChannel(depth int) *Channel {
	return &Channel{
		sync.RWMutex{},
		make(chan interface{}, depth),
		false,
	}
}

func (t *Channel) Enqueue(data interface{}) error {
	t.RLock()
	defer t.RUnlock()
	if t.closed {
		return errors.New("channel closed")
	}
	t.channel <- data
	return nil
}

func (t *Channel) Dequeue() <-chan interface{} {
	return t.channel
}

func (t *Channel) Close() {
	t.Lock()
	defer t.Unlock()
	t.closed = true
	close(t.channel)
}

type RouteList struct {
	*sync.RWMutex
	*list.List
}

type RouteMap map[string]*Channel

var lock = sync.RWMutex{}
var routes = make(RouteMap)

func AddChannel(path string, channel ...*Channel) error {
	lock.Lock()
	defer lock.Unlock()

	log.Printf("Adding channel for path [%s]\n", path)

	if _, ok := routes[path]; !ok {
		routes[path] = RouteList{
			&sync.RWMutex{},
			list.New(),
		}
	}

	routes[path].Lock()
	defer routes[path].Unlock()
	for _, c := range channel {
		routes[path].PushBack(c)
	}

	log.Println("Routes", len(routes))
	for _, v := range routes {
		log.Println(v.Len())
	}

	return nil
}

func CloseChannel(path string) {
	lock.Lock()
	defer lock.Unlock()
{'fraction_non_alphanumeric': 0.1562618236852062, 'fraction_numerical': 0.0, 'mean_word_length': 3.8424908424908426, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5600765', 'n_tokens_mistral': 1018, 'n_tokens_neox': 1001, 'n_words': 248}