<commit_before>#include "nobjectdictionary.h"
#include "../Text/text_buffer.h"
#include "../FileSystem/serializator.h"

NObjectDictionary::NObjectDictionary() : Dictionary<NObject *, NObject *>(compare), NObject()
{
}

NObjectDictionary::~NObjectDictionary()
{
}

int NObjectDictionary::compare(const void *u, const void *v)
{
	NObject **uu = (NObject **)u;
	NObject **vv = (NObject **)v;
	return (*uu)->Compare(**vv);
}

Text NObjectDictionary::ToText()
{
	TextBuffer b;
	for (int i=0; i<numEntries; i++) 
		b.AppendLine(entries[i]->Key->ToText() + ":" + entries[i]->Value->ToText());
	return b.ToText();
}

void NObjectDictionary::Serialize(const Serializator &s)
{
	((Serializator *)&s)->Put(numEntries);
	for (int i=0; i<numEntries; i++) {
		((Serializator *)&s)->Put(*(entries[i]->Key));
		((Serializator *)&s)->Put(*(entries[i]->Value));
	}
}

NObject *NObjectDictionary::Deserialize(const Serializator &s)
{
	
}

NObject *NObjectDictionary::operator [](const NObject *key)
{
	NObject *value = NULL;
	if (!GetKey((NObject *)key, value)) return NULL;
	return value;
}

void NObjectDictionary::SetKey(NObject *key, NObject *value)
{
	if (key == NULL)
		throw new CollectionException("No NULL keys are allowed.", __FILE__, __LINE__, __func__);
	if (value == NULL)
		throw new CollectionException("No NULL values are allowed.", __FILE__, __LINE__, __func__);
		
	Dictionary<NObject *, NObject *>::SetKey(key, value);
}

<commit_msg>Implemented NObject dictionary serialization<commit_after>#include "nobjectdictionary.h"
#include "../Text/text_buffer.h"
#include "../FileSystem/serializator.h"

NObjectDictionary::NObjectDictionary() : Dictionary<NObject *, NObject *>(compare), NObject()
{
}

NObjectDictionary::~NObjectDictionary()
{
}

int NObjectDictionary::compare(const void *u, const void *v)
{
	NObject **uu = (NObject **)u;
	NObject **vv = (NObject **)v;
	return (*uu)->Compare(**vv);
}

Text NObjectDictionary::ToText()
{
	TextBuffer b;
	for (int i=0; i<numEntries; i++) 
		b.AppendLine(entries[i]->Key->ToText() + ":" + entries[i]->Value->ToText());
	return b.ToText();
}

void NObjectDictionary::Serialize(const Serializator &s)
{
	((Serializator *)&s)->Put(numEntries);
	for (int i=0; i<numEntries; i++) {
		((Serializator *)&s)->Put(*(entries[i]->Key));
		((Serializator *)&s)->Put(*(entries[i]->Value));
	}
}

NObject *NObjectDictionary::Deserialize(const Serializator &s)
{
	numEntries = ((Serializator *)&s)->GetInt();
	capacity = numEntries;
	delete entries;
	entries = new DictionaryEntry<NObject *, NObject *> *[capacity];
	for (int i = 0; i < numEntries; i++) {
		NObject *key = ((Serializator *)&s)->GetNObject();
		NObject *value = ((Serializator *)&s)->GetNObject();
		entries[i] = new DictionaryEntry<NObject *, NObject *>(key, value);
	}
}

NObject *NObjectDictionary::operator [](const NObject *key)
{
	NObject *value = NULL;
	if (!GetKey((NObject *)key, value)) return NULL;
	return value;
}

void NObjectDictionary::SetKey(NObject *key, NObject *value)
{
	if (key == NULL)
		throw new CollectionException("No NULL keys are allowed.", __FILE__, __LINE__, __func__);
	if (value == NULL)
		throw new CollectionException("No NULL values are allowed.", __FILE__, __LINE__, __func__);
		
	Dictionary<NObject *, NObject *>::SetKey(key, value);
}


{'fraction_non_alphanumeric': 0.18618159584225008, 'fraction_numerical': 0.001528584530724549, 'mean_word_length': 5.888421052631579, 'pattern_counts': {'":': 2, '<': 14, '<?xml version=': 0, '>': 32, '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': '6193392', 'n_tokens_mistral': 1137, 'n_tokens_neox': 1126, 'n_words': 260}