public override void ReadFromSortedMap(SortedDictionary <int, string> areaCodeMap)
        {
            var descriptionsSet = new HashSet <string>();

            NumOfEntries        = areaCodeMap.Count;
            prefixSizeInBytes   = GetOptimalNumberOfBytesForValue(areaCodeMap.Keys.Last());
            phoneNumberPrefixes = new ByteBuffer(NumOfEntries * prefixSizeInBytes);

            // Fill the phone number prefixes byte buffer, the set of possible lengths of prefixes and the
            // description set.
            var index = 0;
            var possibleLengthsSet = new HashSet <int>();

            foreach (var entry in areaCodeMap)
            {
                var prefix = entry.Key;
                StoreWordInBuffer(phoneNumberPrefixes, prefixSizeInBytes, index, prefix);
                var lengthOfPrefixRef = (int)Math.Log10(prefix) + 1;
                possibleLengthsSet.Add(lengthOfPrefixRef);
                descriptionsSet.Add(entry.Value);
                index++;
            }
            PossibleLengths.Clear();
            PossibleLengths.AddRange(possibleLengthsSet);
            PossibleLengths.Sort();
            CreateDescriptionPool(descriptionsSet, areaCodeMap);
        }
Ejemplo n.º 2
0
        public override void ReadFromSortedMap(SortedDictionary <int, string> sortedAreaCodeMap)
        {
            NumOfEntries        = sortedAreaCodeMap.Count;
            phoneNumberPrefixes = new int[NumOfEntries];
            descriptions        = new string[NumOfEntries];
            var index = 0;
            var possibleLengthsSet = new HashSet <int>();

            foreach (var prefix in sortedAreaCodeMap.Keys)
            {
                phoneNumberPrefixes[index] = prefix;
                descriptions[index]        = sortedAreaCodeMap[prefix];
                index++;
                var lengthOfPrefix = (int)Math.Log10(prefix) + 1;
                possibleLengthsSet.Add(lengthOfPrefix);
            }
            PossibleLengths.Clear();
            PossibleLengths.AddRange(possibleLengthsSet);
            PossibleLengths.Sort();
        }