<commit_before>package meter

import (
	"errors"
	"sync"
)

var (
	ErrDuplicateEvent    = errors.New("Duplicate event registration.")
	ErrNilRegistry       = errors.New("Registry is nil")
	ErrNilEvent          = errors.New("Event is nil")
	ErrNilDesc           = errors.New("Desc is nil")
	ErrUnregisteredEvent = errors.New("Unregistered event")
)

type Registry struct {
	events map[string]Event
	mu     sync.RWMutex
}
type Resolver interface {
	Get(eventName string) Event
}

type ResolverFunc func(eventName string) Event

func (rf ResolverFunc) Get(eventName string) Event {
	return rf(eventName)
}

func NewRegistry() *Registry {
	return &Registry{
		events: make(map[string]Event),
	}
}

var defaultRegistry = NewRegistry()

func (c *Registry) Get(name string) (e Event) {
	c.mu.RLock()
	e = c.events[name]
	c.mu.RUnlock()
	return
}

func (c *Registry) Events() []Event {
	c.mu.RLock()
	events := make([]Event, 0, len(c.events))
	for _, event := range c.events {
		events = append(events, event)
	}
	c.mu.RUnlock()
	return events
}

func (c *Registry) Register(event Event) error {
	if event == nil {
		return ErrNilEvent
	}
	desc := event.Describe()
	if desc == nil {
		return ErrNilDesc
	}
	if err := desc.Error(); err != nil {
		return err
	}
	name := desc.Name()
	c.mu.Lock()
	defer c.mu.Unlock()
	if d, duplicate := c.events[name]; duplicate && d != nil {
		return ErrDuplicateEvent
	}
	c.events[name] = event
	return nil
}

func (c *Registry) MustRegister(event Event) {
	if err := c.Register(event); err != nil {
		panic(err)
	}<commit_msg>Add NewRegistryEvents() and make MustRegister variadic<commit_after>package meter

import (
	"errors"
	"sync"
)

var (
	ErrDuplicateEvent    = errors.New("Duplicate event registration.")
	ErrNilRegistry       = errors.New("Registry is nil")
	ErrNilEvent          = errors.New("Event is nil")
	ErrNilDesc           = errors.New("Desc is nil")
	ErrUnregisteredEvent = errors.New("Unregistered event")
)

type Registry struct {
	events map[string]Event
	mu     sync.RWMutex
}
type Resolver interface {
	Get(eventName string) Event
}

type ResolverFunc func(eventName string) Event

func (rf ResolverFunc) Get(eventName string) Event {
	return rf(eventName)
}

func NewRegistry() *Registry {
	return &Registry{
		events: make(map[string]Event),
	}
}

func NewRegistryEvents(events ...Event) *Registry {
	r := NewRegistry()
	r.MustRegister(events...)
	return r
}

var defaultRegistry = NewRegistry()

func (c *Registry) Get(name string) (e Event) {
	c.mu.RLock()
	e = c.events[name]
	c.mu.RUnlock()
	return
}

func (c *Registry) Events() []Event {
	c.mu.RLock()
	events := make([]Event, 0, len(c.events))
	for _, event := range c.events {
		events = append(events, event)
	}
	c.mu.RUnlock()
	return events
}

func (c *Registry) Register(event Event) error {
	if event == nil {
		return ErrNilEvent
	}
	desc := event.Describe()
	if desc == nil {
		return ErrNilDesc
	}
	if err := desc.Error(); err != nil {
		return err
	}
	name := desc.Name()
	c.mu.Lock()
	defer c.mu.Unlock()
	if d, duplicate := c.events[name]; duplicate && d != nil {
		return ErrDuplicateEvent
	}
	c.events[name] = event
	return nil
}

func (c *Registry) MustRegister(events ...Event) {
	for _, e := range events {
		if err := c.Register(e); err != nil {
			panic(err)
		}
	}
{'fraction_non_alphanumeric': 0.13908290312784694, 'fraction_numerical': 0.0006073489219556636, 'mean_word_length': 3.739568345323741, 'pattern_counts': {'":': 0, '<': 3, '<?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': '3454973', 'n_tokens_mistral': 1174, 'n_tokens_neox': 1152, 'n_words': 312}