<commit_before>package mc_storage

import . "./mc_constants"
import . "./byte_manipulation"

import (
	"log";
)

type storage struct {
	data	map[string]MCItem;
	cas	uint64;
}

func RunServer(input chan MCRequest) {
	var s storage;
	s.cas = 0;
	s.data = make(map[string]MCItem);
	for {
		req := <-input;
		log.Stderrf("Got a request: %s", req);
		req.ResponseChannel <- dispatch(req, &s);
	}
}

func dispatch(req MCRequest, s *storage) (rv MCResponse) {
	switch req.Opcode {
	default:
		rv = notFound(req, s)
	case SET:
		rv = handleSet(req, s)
	case GET:
		rv = handleGet(req, s)
	}
	return;
}

func notFound(req MCRequest, s *storage) MCResponse {
	var response MCResponse;
	response.Status = UNKNOWN_COMMAND;<commit_msg>Use a map of handlers.<commit_after>package mc_storage

import . "./mc_constants"
import . "./byte_manipulation"

import (
	"log";
)

type storage struct {
	data	map[string]MCItem;
	cas	uint64;
}

type handler func(req MCRequest, s *storage) MCResponse

var handlers = map[uint8]handler{
	SET: handleSet,
	GET: handleGet,
}

func RunServer(input chan MCRequest) {
	var s storage;
	s.cas = 0;
	s.data = make(map[string]MCItem);
	for {
		req := <-input;
		log.Stderrf("Got a request: %s", req);
		req.ResponseChannel <- dispatch(req, &s);
	}
}

func dispatch(req MCRequest, s *storage) (rv MCResponse) {
	if h, ok := handlers[req.Opcode]; ok {
		rv = h(req, s)
	} else {
		notFound(req, s)
	}
	return;
}

func notFound(req MCRequest, s *storage) MCResponse {
	var response MCResponse;
	response.Status = UNKNOWN_COMMAND;
{'fraction_non_alphanumeric': 0.13766233766233765, 'fraction_numerical': 0.004545454545454545, 'mean_word_length': 4.102649006622516, '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': '4687545', 'n_tokens_mistral': 610, 'n_tokens_neox': 614, 'n_words': 156}