Beispiel #1
0
        private void Allocate(int capacityFactor)
        {
            if (hashmaps == null)
            {
                hashmaps = new NativeHashMap <TKey, int> [Capacities.Length];
            }
            if (blobHashmaps == null)
            {
                blobHashmaps = new BlobAssetReference <BlobHashMap <TKey, int> > [Capacities.Length];
            }
            if (keys == null)
            {
                keys = new NativeArray <TKey> [Capacities.Length];
            }

            hashMapResult     = new NativeArray <int>(1, Allocator.Persistent);
            blobHashMapResult = new NativeArray <int>(1, Allocator.Persistent);

            for (int i = 0; i < Capacities.Length; i++)
            {
                int capacity = Capacities[i];
                hashmaps[i] = new NativeHashMap <TKey, int>(capacity, Allocator.Persistent);

                BlobBuilder blobBuilder        = new BlobBuilder(Allocator.Temp);
                ref var     root               = ref blobBuilder.ConstructRoot <BlobHashMap <TKey, int> >();
                var         blobBuilderHashmap = blobBuilder.AllocateHashMap(ref root, capacity, capacityFactor);


                keys[i] = new NativeArray <TKey>(capacity * 2, Allocator.Persistent);
                Fill(keys[i], hashmaps[i], ref blobBuilderHashmap, capacity);

                // create the blob ref
                blobHashmaps[i] = blobBuilder.CreateBlobAssetReference <BlobHashMap <TKey, int> >(Allocator.Persistent);
            }