Permalink
Browse files

more dir

  • Loading branch information...
1 parent 7373c9a commit 2e3636f4f5781c13ee69b94ff356200ad8815932 @neuecc committed Jan 8, 2017
Showing 398 changed files with 4 additions and 9,428 deletions.
View
@@ -109,7 +109,7 @@ UpgradeLog*.XML
.vs/restore.dg
# Unity
-src/MasterMemory.Unity/bin/*
-src/MasterMemory.Unity/Library/*
-src/MasterMemory.Unity/obj/*
-src/MasterMemory.Unity/Temp/*
+src/MasterMemory.UnityClient/bin/*
+src/MasterMemory.UnityClient/Library/*
+src/MasterMemory.UnityClient/obj/*
+src/MasterMemory.UnityClient/Temp/*
@@ -1,9 +0,0 @@
-fileFormatVersion: 2
-guid: 069a76088dcfaf945af33c17b9ac4d93
-folderAsset: yes
-timeCreated: 1483860007
-licenseType: Pro
-DefaultImporter:
- userData:
- assetBundleName:
- assetBundleVariant:
@@ -1,193 +0,0 @@
-using System;
-using System.Collections.Generic;
-using ZeroFormatter;
-using ZeroFormatter.Formatters;
-using ZeroFormatter.Internal;
-
-namespace MasterMemory
-{
- // Memory Layout:
- // [MemoryCount:int][(key:string,memoryOffset:index)][memory...]
-
- public class Database
- {
- readonly Dictionary<string, ISerializableMemory> memories; // as readonly
- readonly bool useNullTracker;
-
- public int MemoryCount
- {
- get { return memories.Count; }
- }
-
- public ICollection<string> Keys
- {
- get { return memories.Keys; }
- }
-
- public Memory<TKey, TElement> GetMemory<TKey, TElement>(string memoryKey, Func<TElement, TKey> indexSelector)
- {
- lock (memories)
- {
- ISerializableMemory obj;
- if (!memories.TryGetValue(memoryKey, out obj))
- {
- throw new KeyNotFoundException("MemoryKey Not Found:" + memoryKey);
- }
-
- var byteOffsetMemory = obj as ArraySegmentMemory;
- if (byteOffsetMemory != null)
- {
- var tracker = useNullTracker ? DirtyTracker.NullTracker : new DirtyTracker();
- var memory = byteOffsetMemory.ToMemory<TKey, TElement>(tracker, indexSelector);
- memories[memoryKey] = memory;
- return memory;
- }
- else
- {
- var memory = obj as Memory<TKey, TElement>;
- if (memory == null)
- {
- throw new ArgumentException("Cast type is invalid, actual memory type:" + obj.GetType().Name);
- }
- return memory;
- }
- }
- }
-
- internal Database(IEnumerable<KeyValuePair<string, ISerializableMemory>> memories)
- {
- this.memories = new Dictionary<string, ISerializableMemory>(StringComparer.OrdinalIgnoreCase);
- foreach (var item in memories)
- {
- this.memories.Add(item.Key, item.Value);
- }
- this.useNullTracker = true;
- }
-
- Database(Dictionary<string, ISerializableMemory> memories, bool useNullTracker)
- {
- this.memories = memories;
- this.useNullTracker = useNullTracker;
- }
-
- /// <summary>
- /// Create database from underlying bytes.
- /// If all objects are readonly, set guaranteedAllObjectsAreReadonly = true for improve performance.
- /// </summary>
- public static Database Open(byte[] bytes, bool guaranteedAllObjectsAreReadonly = false)
- {
- var memoryCount = BinaryUtil.ReadInt32(ref bytes, 0);
- var stringFormatter = ZeroFormatter.Formatters.Formatter<DefaultResolver, string>.Default;
-
- var memories = new Dictionary<string, ISerializableMemory>(memoryCount, StringComparer.OrdinalIgnoreCase);
- var offset = 4;
-
- string prevKeyName = null;
- int prevMemoryOffset = 0;
- for (int i = 0; i < memoryCount; i++)
- {
- int byteSize;
- var keyName = stringFormatter.Deserialize(ref bytes, offset, DirtyTracker.NullTracker, out byteSize);
- offset += byteSize;
- var memoryOffset = BinaryUtil.ReadInt32(ref bytes, offset);
- offset += 4;
-
- if (memoryCount == 1 || i == memoryCount - 1)
- {
- memories.Add(keyName, new ArraySegmentMemory(new ArraySegment<byte>(bytes, memoryOffset, bytes.Length - memoryOffset)));
- }
- if (i != 0)
- {
- memories.Add(prevKeyName, new ArraySegmentMemory(new ArraySegment<byte>(bytes, prevMemoryOffset, memoryOffset - prevMemoryOffset)));
- }
-
- prevKeyName = keyName;
- prevMemoryOffset = memoryOffset;
- }
-
- return new Database(memories, guaranteedAllObjectsAreReadonly);
- }
-
- public byte[] Save()
- {
- lock (memories)
- {
- var bytes = new byte[255]; // initial
- var list = new List<HeaderRecord>();
-
- var offset = 0;
- offset += ZeroFormatter.Internal.BinaryUtil.WriteInt32(ref bytes, 0, MemoryCount);
-
- // headers
- foreach (var item in memories)
- {
- var stringFormatter = ZeroFormatter.Formatters.Formatter<DefaultResolver, string>.Default;
- offset += stringFormatter.Serialize(ref bytes, offset, item.Key);
- list.Add(new HeaderRecord { HeaderOffset = offset, Memory = item.Value });
- offset += 4;
- }
-
- // memories
- foreach (var item in list)
- {
- BinaryUtil.WriteInt32Unsafe(ref bytes, item.HeaderOffset, offset);
- offset += item.Memory.Serialize(ref bytes, offset);
- }
-
- BinaryUtil.FastResize(ref bytes, offset);
- return bytes;
- }
- }
-
- public DatabaseBuilder ToBuilder()
- {
- var builder = new DatabaseBuilder();
- foreach (var item in memories)
- {
- builder.InternalAdd(item.Key, item.Value);
- }
- return builder;
- }
-
- struct HeaderRecord
- {
- public int HeaderOffset;
- public ISerializableMemory Memory;
- }
- }
-
- public class DatabaseBuilder
- {
- readonly Dictionary<string, ISerializableMemory> memories = new Dictionary<string, ISerializableMemory>(StringComparer.OrdinalIgnoreCase);
-
- public DatabaseBuilder()
- {
-
- }
-
- internal void InternalAdd(string key, ISerializableMemory memory)
- {
- memories.Add(key, memory);
- }
-
- public void Add<TKey, TElement>(string key, IEnumerable<TElement> datasource, Func<TElement, TKey> primaryIndexSelector)
- {
- memories.Add(key, new Memory<TKey, TElement>(datasource, primaryIndexSelector));
- }
-
- public void Replace<TKey, TElement>(string key, IEnumerable<TElement> datasource, Func<TElement, TKey> primaryIndexSelector)
- {
- memories[key] = new Memory<TKey, TElement>(datasource, primaryIndexSelector);
- }
-
- public void Remove(string key)
- {
- memories.Remove(key);
- }
-
- public Database Build()
- {
- return new Database(memories);
- }
- }
-}
@@ -1,12 +0,0 @@
-fileFormatVersion: 2
-guid: 4decb22917bb9b84e9cf4841a2d80ad1
-timeCreated: 1483865553
-licenseType: Pro
-MonoImporter:
- serializedVersion: 2
- defaultReferences: []
- executionOrder: 0
- icon: {instanceID: 0}
- userData:
- assetBundleName:
- assetBundleVariant:
@@ -1,9 +0,0 @@
-fileFormatVersion: 2
-guid: d7e21c4ee8ebc784ca854c62fab88fa2
-folderAsset: yes
-timeCreated: 1483860069
-licenseType: Pro
-DefaultImporter:
- userData:
- assetBundleName:
- assetBundleVariant:
@@ -1,129 +0,0 @@
-using System;
-using System.Collections.Generic;
-
-namespace MasterMemory.Internal
-{
- public static class BinarySearch
- {
- public static int FindFirst<T, TKey>(IList<T> array, TKey key, Func<T, TKey> selector, IComparer<TKey> comparer)
- {
- var lo = 0;
- var hi = array.Count - 1;
-
- while (lo <= hi)
- {
- var mid = lo + ((hi - lo) >> 1);
- var found = comparer.Compare(selector(array[mid]), key);
-
- if (found == 0) return mid;
- if (found < 0)
- {
- lo = mid + 1;
- }
- else
- {
- hi = mid - 1;
- }
- }
-
- return -1;
- }
-
- // lo = 0, hi = Count.
- public static int FindClosest<T, TKey>(IList<T> array, int lo, int hi, TKey key, Func<T, TKey> selector, IComparer<TKey> comparer, bool selectLower)
- {
- if (array.Count == 0) return -1;
-
- var originalHi = hi;
- lo = lo - 1;
-
- while (hi - lo > 1)
- {
- var mid = lo + ((hi - lo) >> 1);
- var found = comparer.Compare(selector(array[mid]), key);
-
- if (found == 0)
- {
- lo = hi = mid;
- break;
- }
- if (found >= 1)
- {
- hi = mid;
- }
- else
- {
- lo = mid;
- }
- }
-
- if (selectLower)
- {
- return (lo < 0) ? 0 : lo;
- }
- else
- {
- return (originalHi <= hi) ? originalHi - 1 : hi;
- }
- }
-
- // default lo = 0, hi = array.Count
- public static int LowerBound<T, TKey>(IList<T> array, int lo, int hi, TKey key, Func<T, TKey> selector, IComparer<TKey> comparer)
- {
- while (lo < hi)
- {
- var mid = lo + ((hi - lo) >> 1);
- var found = comparer.Compare(key, selector(array[mid]));
-
- if (found <= 0)
- {
- hi = mid;
- }
- else
- {
- lo = mid + 1;
- }
- }
-
- var index = lo;
- if (index == -1 || array.Count <= index)
- {
- return -1;
- }
-
- // check final
- return (comparer.Compare(key, selector(array[index])) == 0)
- ? index
- : -1;
- }
-
- public static int UpperBound<T, TKey>(IList<T> array, int lo, int hi, TKey key, Func<T, TKey> selector, IComparer<TKey> comparer)
- {
- while (lo < hi)
- {
- var mid = lo + ((hi - lo) >> 1);
- var found = comparer.Compare(key, selector(array[mid]));
-
- if (found >= 0)
- {
- lo = mid + 1;
- }
- else
- {
- hi = mid;
- }
- }
-
- var index = (lo == 0) ? 0 : lo - 1;
- if (index == -1 || array.Count <= index)
- {
- return -1;
- }
-
- // check final
- return (comparer.Compare(key, selector(array[index])) == 0)
- ? index
- : -1;
- }
- }
-}
@@ -1,12 +0,0 @@
-fileFormatVersion: 2
-guid: 8a28e50bfc8e99141b2c0044bc9e7bc6
-timeCreated: 1483865542
-licenseType: Pro
-MonoImporter:
- serializedVersion: 2
- defaultReferences: []
- executionOrder: 0
- icon: {instanceID: 0}
- userData:
- assetBundleName:
- assetBundleVariant:
Oops, something went wrong.

0 comments on commit 2e3636f

Please sign in to comment.