Beispiel #1
0
        /// <inheritdoc/>
        public SharedConfig <TProxy> Lookup <TType, TKey, TProxy>(ICodegenKey <TType, TKey, TProxy> codegenKey)
            where TType : ICodegenType, new()
            where TKey : ICodegenKey, new()
            where TProxy : ICodegenProxy <TType, TProxy>, new()
        {
            uint slotIndex = 0;

            return(MlosProxyInternal.SharedConfigDictionaryLookup <ProbingPolicy> .Get <TProxy>(SharedConfigDictionary, codegenKey, ref slotIndex));
        }
Beispiel #2
0
        /// <inheritdoc/>
        public SharedConfig <TProxy> Lookup <TType, TKey, TProxy>(ICodegenKey <TType, TKey, TProxy> codegenKey)
            where TType : ICodegenType, new()
            where TKey : ICodegenKey, new()
            where TProxy : ICodegenProxy <TType, TProxy>, new()
        {
            uint slotIndex = 0;

            return(sharedConfigMemoryRegion.Get <ProbingPolicy, TProxy>(codegenKey, ref slotIndex));
        }
        /// <summary>
        /// Internal lookup. TProxy type is deduced by the caller.
        /// </summary>
        /// <typeparam name="TProbingPolicy">HashTable lookup policy.</typeparam>
        /// <typeparam name="TProxy">Codegen proxy type.</typeparam>
        /// <param name="sharedConfigMemoryRegion"></param>
        /// <param name="codegenKey"></param>
        /// <param name="slotIndex"></param>
        /// <returns></returns>
        public static SharedConfig <TProxy> Get <TProbingPolicy, TProxy>(
            this SharedConfigMemoryRegion sharedConfigMemoryRegion,
            ICodegenKey codegenKey,
            ref uint slotIndex)
            where TProbingPolicy : IProbingPolicy
            where TProxy : ICodegenProxy, new()
        {
            TProbingPolicy probingPolicy = default;

            uint probingCount = 0;

            slotIndex = 0;

            var configsArray = new UIntArray()
            {
                Buffer = sharedConfigMemoryRegion.Buffer + (int)sharedConfigMemoryRegion.ConfigsArrayOffset
            };

            uint elementCount = configsArray.Count;
            ProxyArray <uint> sharedConfigsOffsets = configsArray.Elements;

            SharedConfig <TProxy> sharedConfig = default;

            while (true)
            {
                slotIndex = probingPolicy.CalculateIndex(codegenKey, ref probingCount, elementCount);

                uint sharedConfigOffsets = sharedConfigsOffsets[(int)slotIndex];

                if (sharedConfigOffsets == 0)
                {
                    // Slot entry is empty.
                    //
                    sharedConfig.Buffer = IntPtr.Zero;
                    break;
                }

                // Compare the object keys.
                // Create a proxy to the shared config.
                //
                sharedConfig.Buffer = sharedConfigMemoryRegion.Buffer + (int)sharedConfigOffsets;

                // Compare key with the proxy.
                //
                bool foundEntry = codegenKey.CodegenTypeIndex() == sharedConfig.Header.CodegenTypeIndex &&
                                  codegenKey.CompareKey(sharedConfig.Config);
                if (foundEntry)
                {
                    break;
                }

                ++probingCount;
            }

            return(sharedConfig);
        }
        /// <summary>
        /// Internal lookup. TProxy type is deduced by the caller.
        /// </summary>
        /// <typeparam name="TProxy">Codegen proxy type.</typeparam>
        /// <param name="sharedConfigDictionary"></param>
        /// <param name="codegenKey"></param>
        /// <param name="slotIndex"></param>
        /// <returns></returns>
        internal static SharedConfig <TProxy> Get <TProxy>(
            SharedConfigDictionary sharedConfigDictionary,
            ICodegenKey codegenKey,
            ref uint slotIndex)
            where TProxy : ICodegenProxy, new()
        {
            TProbingPolicy probingPolicy = default;

            uint probingCount = 0;

            slotIndex = 0;

            UIntArray configsArray = sharedConfigDictionary.ConfigsOffsetArray;

            uint elementCount = configsArray.Count;
            ProxyArray <uint> sharedConfigsOffsets = configsArray.Elements;

            SharedConfig <TProxy> sharedConfig = default;

            while (true)
            {
                slotIndex = probingPolicy.CalculateIndex(codegenKey, ref probingCount, elementCount);

                uint offsetToSharedConfig = sharedConfigsOffsets[(int)slotIndex];

                if (offsetToSharedConfig == 0)
                {
                    // Slot entry is empty.
                    //
                    sharedConfig.Buffer = IntPtr.Zero;
                    break;
                }

                // Compare the object keys.
                // Create a proxy to the shared config.
                //
                sharedConfig.Buffer = sharedConfigDictionary.Buffer - sharedConfigDictionary.Allocator.OffsetToAllocator + (int)offsetToSharedConfig;

                // Compare key with the proxy.
                //
                bool foundEntry = codegenKey.CodegenTypeIndex() == sharedConfig.Header.CodegenTypeIndex &&
                                  codegenKey.CompareKey(sharedConfig.Config);
                if (foundEntry)
                {
                    break;
                }

                ++probingCount;
            }

            return(sharedConfig);
        }
Beispiel #5
0
        /// <inheritdoc/>
        public uint CalculateIndex(ICodegenKey codegenKey, ref uint probingCount, uint elementCount)
        {
            uint hashValue = codegenKey.GetKeyHashValue <THash>();

            return((hashValue + probingCount++) % elementCount);
        }