<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

using Kyru.Network;

namespace Kyru.Core
{
	/// <summary>
	/// This class keeps track of all kyru objects on the file system. Note that not all objects have to be in memory.
	/// </summary>
	internal class KObjectSet
	{
		private Config config;

		/// <summary>
		/// Currently not in use.
		/// The cache can give a list of some items that are in memory such that retrieving them is faster.
		/// </summary>
		private Dictionary<KademliaId, KObject> cache;

		public KObjectSet(Config config) {
			this.config = config;
		}

		/// <summary>
		/// Retrieve an object from.
		/// </summary>
		/// <param name="id">The id of the object</param>
		/// <returns>The object, or null if he can't find it</returns>
		internal T Get<T>(KademliaId id) where T : KObject , new()
		{
			var idString = id.ToString();
			String path = Path.Combine(config.storeDirectory, idString + ".obj");
			FileStream fs;
			try
			{
				fs = new FileStream(path, FileMode.Open);
			} catch (FileNotFoundException) {
				return null;
			}
			T returnValue = new T();
			returnValue.Read(fs);
			return returnValue;
		}

		/// <summary>
		/// Method to retrieve a list of items.
		/// </summary>
		/// <param name="ids">A list of id's for the given item</param>
		/// <param name="strict">Wheter incomplete lists are allowed</param>
		/// <returns></returns>
		internal List<T> GetList<T>(List<KademliaId> ids, bool strict = false) where T : KObject, new()
		{
			List<T> returnList = new List<T>();
			foreach (var id in ids) {
				var item = Get<T>(id);
				if (item == null && strict == true)
					return null;

				if (item != null) {
					returnList.Add(item);
				}
			}
			return returnList;
		}

		/// <summary>
		/// Add an object to the file system.
		/// </summary>
		/// <param name="obj">The object to be added</param>
		internal void Store(KObject obj)
		{
			var idString = obj.Id.ToString();
			String path = Path.Combine(config.storeDirectory, idString + ".obj");
			FileStream fs = new FileStream(path, FileMode.Create);
			obj.Write(fs);
		}

		/// <summary>
		/// Deletes a file on the file system
		/// </summary>
		/// <param name="id">The id of the file to be deleted</param>
		internal void Delete(KademliaId id)
		{
			var idString = id.ToString();
			String path = Path.Combine(config.storeDirectory, idString + ".obj");
			File.Delete(path);
		}
	}
}
<commit_msg>Disable KObjectSet.Get and .Store due to compile error<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

using Kyru.Network;

namespace Kyru.Core
{
	/// <summary>
	/// This class keeps track of all kyru objects on the file system. Note that not all objects have to be in memory.
	/// </summary>
	internal class KObjectSet
	{
		private Config config;

		/// <summary>
		/// Currently not in use.
		/// The cache can give a list of some items that are in memory such that retrieving them is faster.
		/// </summary>
		private Dictionary<KademliaId, KObject> cache;

		public KObjectSet(Config config) {
			this.config = config;
		}

		/// <summary>
		/// Retrieve an object from.
		/// </summary>
		/// <param name="id">The id of the object</param>
		/// <returns>The object, or null if he can't find it</returns>
		internal T Get<T>(KademliaId id) where T : KObject , new()
		{
			var idString = id.ToString();
			String path = Path.Combine(config.storeDirectory, idString + ".obj");
			FileStream fs;
			try
			{
				fs = new FileStream(path, FileMode.Open);
			} catch (FileNotFoundException) {
				return null;
			}
			throw new NotImplementedException();
			//T returnValue = new T();
			//returnValue.Read(fs);
			//return returnValue;
		}

		/// <summary>
		/// Method to retrieve a list of items.
		/// </summary>
		/// <param name="ids">A list of id's for the given item</param>
		/// <param name="strict">Wheter incomplete lists are allowed</param>
		/// <returns></returns>
		internal List<T> GetList<T>(List<KademliaId> ids, bool strict = false) where T : KObject, new()
		{
			List<T> returnList = new List<T>();
			foreach (var id in ids) {
				var item = Get<T>(id);
				if (item == null && strict == true)
					return null;

				if (item != null) {
					returnList.Add(item);
				}
			}
			return returnList;
		}

		/// <summary>
		/// Add an object to the file system.
		/// </summary>
		/// <param name="obj">The object to be added</param>
		internal void Store(KObject obj)
		{
			var idString = obj.Id.ToString();
			String path = Path.Combine(config.storeDirectory, idString + ".obj");
			throw new NotImplementedException();
			//FileStream fs = new FileStream(path, FileMode.Create);
			//obj.Write(fs);
		}

		/// <summary>
		/// Deletes a file on the file system
		/// </summary>
		/// <param name="id">The id of the file to be deleted</param>
		internal void Delete(KademliaId id)
		{
			var idString = id.ToString();
			String path = Path.Combine(config.storeDirectory, idString + ".obj");
			File.Delete(path);
		}
	}
}

{'fraction_non_alphanumeric': 0.1392620624408704, 'fraction_numerical': 0.0, 'mean_word_length': 2.4914134742404226, 'pattern_counts': {'":': 0, '<': 71, '<?xml version=': 0, '>': 71, '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': '2936230', 'n_tokens_mistral': 1890, 'n_tokens_neox': 1630, 'n_words': 529}