Пример #1
0
 /// <summary>
 /// Create a new writer for each compilation
 /// </summary>
 public NanCodeWriter()
 {
     ReturnsValues = false;
     _stringTable  = new List <string>(100);
     _opcodes      = new List <double>(1024);
     _symbols      = new HashLookup <string>();
 }
Пример #2
0
 /// <summary>
 /// Add a symbol set to the known symbols table
 /// </summary>
 public void AddSymbols(HashLookup <string> sym)
 {
     foreach (var symbol in sym)
     {
         AddSymbol(symbol.Key, symbol.Value);
     }
 }
Пример #3
0
        /// <summary>
        /// Returns a <see cref="ILookup{TKey, TElement}"/> that maps a <typeparamref name="TKey"/> to zero or more <typeparamref name="TValue"/>
        /// </summary>
        public static HashLookup <TKey, TValue> ToLookup <TKey, TValue>(this DbDataReader reader, Func <DbDataReader, TKey> keySelector, Func <DbDataReader, TValue> valueSelector)
        {
            var lookup = new HashLookup <TKey, TValue>();

            while (reader.Read())
            {
                var key   = keySelector(reader);
                var value = valueSelector(reader);
                lookup.Add(key, value);
            }
            return(lookup);
        }
Пример #4
0
        /// <summary>Returns a <see cref="HashLookup{TKey, TElement}"/> containing all the items in the sequence grouped by key</summary>
        public async static Task <HashLookup <TKey, TValue> > ToLookupAsync <TKey, TValue>(this IAsyncEnumerator <TValue> source, Func <TValue, TKey> keyFunc, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }
            var result = new HashLookup <TKey, TValue>();

            while (await source.MoveNextAsync(cancellationToken))
            {
                var key = keyFunc(source.Current);
                result.Add(key, source.Current);
            }
            return(result);
        }
Пример #5
0
        public void TestHashLookup()
        {
            uint b = 0, c = 0;

            var byteEmpty = new byte[0];

            HashLookup.Hash(byteEmpty, ref c, ref b);
            Assert.AreEqual(b, 0xdeadbeef);
            Assert.AreEqual(c, 0xdeadbeef);

            b = 0xdeadbeef;
            c = 0;
            HashLookup.Hash(new byte[0], ref c, ref b);
            Assert.AreEqual(b, 0xdeadbeef);
            Assert.AreEqual(c, 0xbd5b7dde);

            b = 0xdeadbeef;
            c = 0xdeadbeef;
            HashLookup.Hash(new byte[0], ref c, ref b);
            Assert.AreEqual(b, 0xbd5b7dde);
            Assert.AreEqual(c, 0x9c093ccd);

            byte[] byteData = Encoding.UTF8.GetBytes("Four score and seven years ago");

            b = 0;
            c = 0;
            HashLookup.Hash(byteData, ref c, ref b);
            Assert.AreEqual(b, 0xce7226e6);
            Assert.AreEqual(c, 0x17770551);

            b = 1;
            c = 0;
            HashLookup.Hash(byteData, ref c, ref b);
            Assert.AreEqual(b, 0xbd371de4);
            Assert.AreEqual(c, 0xe3607cae);

            b = 0;
            c = 1;
            HashLookup.Hash(byteData, ref c, ref b);
            Assert.AreEqual(b, 0x6cbea4b3);
            Assert.AreEqual(c, 0xcd628161);

            c = HashLookup.Hash(byteData, 0);
            Assert.AreEqual(c, 0x17770551);

            c = HashLookup.Hash(byteData, 1);
            Assert.AreEqual(c, 0xcd628161);
        }
Пример #6
0
    public PrefabLookup(string bundlename)
    {
        backend = new AssetBundleBackend(bundlename);

        var lookupAsset = backend.Load <TextAsset>(lookupPath);

        lookup = new HashLookup(lookupAsset.text);

        var asyncOperation = SceneManager.LoadSceneAsync(scenePath, LoadSceneMode.Additive);

        scene = SceneManager.GetSceneAt(SceneManager.sceneCount - 1);

        asyncOperation.completed += (operation) =>
        {
            foreach (var go in scene.GetRootGameObjects())
            {
                prefabs.Add(lookup[go.name], go);
            }
        };
    }
Пример #7
0
 public static void SetRelationship <T, TKey, TOther, TOther2>(this IEnumerable <T> source, Func <T, TKey> keyExtractor, HashLookup <TKey, TOther> details, Action <T, IReadOnlyList <TOther> > mutator, HashLookup <TKey, TOther2> details2, Action <T, IReadOnlyList <TOther2> > mutator2)
 {
     foreach (var item in source)
     {
         var key = keyExtractor(item);
         mutator(item, details[key]);
         mutator2(item, details2[key]);
     }
 }