Commits

alexdavies74  committed f559c85

Genericify the data store, it was too ugly that strings were the only thing it could store

  • Participants
  • Parent commits b3b9234

Comments (0)

Files changed (2)

File DataStoreChallenge/DataStore.cs

 
 namespace DataStoreChallenge
 {
-    class DataStore
+    class DataStore<TKey, TValue> where TKey : IComparable where TValue : class
     {
         /// <summary>
         /// The data store is implemented using an immutable map. This allows fast adding and reading of values (log n)
         /// but also allows us to instantaneously snapshot the contents of the map at any time, which is useful for the transactions.
         /// </summary>
-        private FSharpMap<string, string> m_Data = new FSharpMap<string, string>(Enumerable.Empty<Tuple<string, string>>());
+        private FSharpMap<TKey, TValue> m_Data = new FSharpMap<TKey, TValue>(Enumerable.Empty<Tuple<TKey, TValue>>());
 
-        public void Set(string key, string value)
+        public void Set(TKey key, TValue value)
         {
             m_Data = m_Data.Add(key, value);
         }
         /// <summary>
         /// Returns null if the key didn't exist
         /// </summary>
-        public string Get(string key)
+        public TValue Get(TKey key)
         {
-            FSharpOption<string> maybeValue = m_Data.TryFind(key);
-            return maybeValue == FSharpOption<string>.None ? null : maybeValue.Value;
+            FSharpOption<TValue> maybeValue = m_Data.TryFind(key);
+            return maybeValue == FSharpOption<TValue>.None ? null : maybeValue.Value;
         }
 
-        public void UnSet(string key)
+        public void UnSet(TKey key)
         {
             m_Data = m_Data.Remove(key);
         }

File DataStoreChallenge/Tests/DataStoreTests.cs

-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using NUnit.Framework;
+using NUnit.Framework;
 
 namespace DataStoreChallenge.Tests
 {
     [TestFixture]
     class DataStoreTests
     {
-        private DataStore m_DataStore;
+        private DataStore<string, string> m_DataStore;
 
         [SetUp]
         public void SetUp()
         {
-            m_DataStore = new DataStore();
+            m_DataStore = new DataStore<string, string>();
         }
 
         [Test]