#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements.  See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License.  You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from collections import deque
from dataclasses import dataclass

MIN_ENUM_STRING_LENGTH = 3
MAX_INDEX_LENGTH = 0xffff

class YajbeEncoderEnumConfig:
    TYPE = None

class YajbeEnumLruConfig(YajbeEncoderEnumConfig):
    TYPE = 'LRU'

    def __init__(self, lru_size, min_freq):
        self.lru_size = lru_size
        self.min_freq = min_freq

@dataclass
class EnumLruItem:
  key: str
  freq: int

class EnumLruMapping:
    def __init__(self, lru_size, min_freq) -> None:
        self.lru_size = lru_size
        self.min_freq = min_freq
        self._lru = deque(maxlen=lru_size)
        self._lru_map = {}
        self._index_map = {}
        self._indexed = []

    def get(self, index: int) -> str:
        return self._indexed[index]

    def add(self, key: str) -> int:
        if len(key) < MIN_ENUM_STRING_LENGTH: return -1

        key_index = self._index_map.get(key)
        if key_index is not None: return key_index

        if len(self._indexed) == MAX_INDEX_LENGTH:
            return -1

        item = self._lru_map.get(key)
        if item is None:
            if len(self._lru) == self.lru_size:
                evict_item = self._lru.pop()
                del self._lru_map[evict_item.key]

            new_item = EnumLruItem(key, 1)
            self._lru.appendleft(new_item)
            self._lru_map[new_item.key] = new_item
            return -1

        self._lru.remove(item)
        item.freq += 1
        if item.freq >= self.min_freq:
            new_index = len(self._index_map)
            self._indexed.append(item.key)
            self._index_map[item.key] = new_index
            #print('add to index map', len(self._index_map), item.key, new_index)
            del self._lru_map[item.key]
        else:
          self._lru.appendleft(item)
        return -1

if __name__ == '__main__':
    data = ["2022-12", "bedfordshire", "btp", "cambridgeshire", "city-of-london", "cleveland", "cumbria", "derbyshire", "dorset", "durham", "dyfed-powys", "essex", "gloucestershire", "gwent", "hampshire", "hertfordshire", "kent", "lancashire", "leicestershire", "lincolnshire", "merseyside", "norfolk", "north-wales", "north-yorkshire", "northamptonshire", "northumbria", "south-yorkshire", "staffordshire", "suffolk", "surrey", "sussex", "thames-valley", "west-mercia", "west-midlands", "west-yorkshire", "2022-11", "bedfordshire", "btp", "cambridgeshire", "city-of-london", "cleveland", "cumbria", "derbyshire", "dorset", "durham", "dyfed-powys", "essex", "gloucestershire", "gwent", "hampshire", "hertfordshire", "kent", "lancashire", "leicestershire", "lincolnshire", "merseyside", "norfolk", "north-wales", "north-yorkshire", "northamptonshire", "northumbria", "south-yorkshire", "staffordshire", "suffolk", "surrey", "sussex", "thames-valley", "west-mercia", "west-midlands", "west-yorkshire", "2022-10", "bedfordshire", "btp", "cambridgeshire", "city-of-london", "cleveland", "cumbria", "derbyshire", "devon-and-cornwall", "dorset", "durham", "dyfed-powys", "essex", "gloucestershire", "gwent", "hampshire", "hertfordshire", "kent", "lancashire", "leicestershire", "lincolnshire", "merseyside", "metropolitan", "norfolk", "north-wales", "north-yorkshire", "northamptonshire", "northumbria", "south-yorkshire", "staffordshire", "suffolk", "surrey", "sussex", "thames-valley", "west-mercia", "west-midlands", "west-yorkshire", "2022-09", "bedfordshire", "btp", "cambridgeshire", "city-of-london", "cleveland", "cumbria", "derbyshire", "devon-and-cornwall", "dorset", "durham", "dyfed-powys", "essex", "gloucestershire", "gwent", "hampshire", "hertfordshire", "kent", "lancashire", "leicestershire", "lincolnshire", "merseyside", "metropolitan", "norfolk", "north-wales", "north-yorkshire", "northamptonshire", "northumbria", "nottinghamshire", "south-yorkshire", "staffordshire", "suffolk", "surrey", "sussex", "thames-valley", "west-mercia", "west-midlands", "west-yorkshire", "2022-08", "bedfordshire", "btp", "cambridgeshire", "city-of-london", "cleveland", "cumbria", "derbyshire", "devon-and-cornwall", "dorset", "durham", "dyfed-powys", "essex", "gloucestershire", "gwent", "hampshire", "hertfordshire", "kent", "lancashire", "leicestershire", "lincolnshire", "merseyside", "metropolitan", "norfolk", "north-wales", "north-yorkshire", "northamptonshire", "northumbria", "nottinghamshire", "south-wales", "south-yorkshire", "staffordshire", "suffolk", "surrey", "sussex", "thames-valley", "west-mercia", "west-midlands", "west-yorkshire", "wiltshire", "2022-07", "bedfordshire", "btp", "cambridgeshire", "city-of-london", "cleveland", "cumbria", "derbyshire", "devon-and-cornwall", "dorset", "durham", "dyfed-powys", "essex", "gloucestershire", "gwent", "hampshire", "hertfordshire", "kent", "lancashire", "leicestershire", "lincolnshire", "merseyside", "metropolitan", "norfolk", "north-wales", "north-yorkshire", "northamptonshire", "northumbria", "nottinghamshire", "south-wales", "south-yorkshire", "staffordshire", "suffolk", "surrey", "sussex", "thames-valley", "west-mercia", "west-midlands", "west-yorkshire", "wiltshire", "2022-06", "avon-and-somerset", "bedfordshire", "btp", "cambridgeshire", "city-of-london", "cleveland", "cumbria", "derbyshire", "devon-and-cornwall", "dorset", "durham", "dyfed-powys", "essex", "gloucestershire", "gwent", "hampshire", "hertfordshire", "kent", "lancashire", "leicestershire", "lincolnshire", "merseyside", "norfolk", "north-wales", "north-yorkshire", "northamptonshire", "northumbria", "nottinghamshire", "south-wales", "south-yorkshire", "staffordshire", "suffolk", "surrey", "sussex", "thames-valley", "west-mercia", "west-midlands", "west-yorkshire", "wiltshire", "2022-05", "avon-and-somerset", "bedfordshire", "btp", "cambridgeshire", "city-of-london", "cleveland", "cumbria", "derbyshire", "devon-and-cornwall", "dorset", "durham", "dyfed-powys", "essex", "gloucestershire", "gwent", "hampshire", "hertfordshire", "kent", "lancashire", "leicestershire", "lincolnshire", "merseyside", "metropolitan", "norfolk", "north-wales", "north-yorkshire", "northamptonshire", "northumbria", "nottinghamshire", "south-wales", "south-yorkshire", "staffordshire", "suffolk", "surrey", "sussex", "thames-valley", "west-mercia", "west-midlands", "west-yorkshire", "wiltshire", "2022-04", "avon-and-somerset", "bedfordshire", "btp", "cambridgeshire", "city-of-london", "cleveland", "cumbria", "derbyshire", "devon-and-cornwall", "dorset", "durham", "dyfed-powys", "essex", "gloucestershire", "gwent", "hampshire", "hertfordshire", "humberside", "kent", "lancashire", "leicestershire", "lincolnshire", "merseyside", "metropolitan", "norfolk", "north-wales", "north-yorkshire", "northamptonshire", "northumbria", "nottinghamshire", "south-wales", "south-yorkshire", "staffordshire", "suffolk", "surrey", "sussex", "thames-valley", "west-mercia", "west-midlands", "west-yorkshire", "wiltshire", "2022-03", "avon-and-somerset", "bedfordshire", "btp", "cambridgeshire", "city-of-london", "cleveland", "cumbria", "derbyshire", "devon-and-cornwall", "dorset", "durham", "dyfed-powys", "essex", "gloucestershire", "gwent", "hampshire", "hertfordshire", "humberside", "kent", "lancashire", "leicestershire", "lincolnshire", "merseyside", "metropolitan", "norfolk", "north-wales", "north-yorkshire", "northamptonshire", "northumbria", "nottinghamshire", "south-wales", "south-yorkshire", "staffordshire", "suffolk", "surrey", "sussex", "thames-valley", "warwickshire", "west-mercia", "west-midlands", "west-yorkshire", "wiltshire", "2022-02", "avon-and-somerset", "bedfordshire", "btp", "cambridgeshire", "city-of-london", "cleveland", "cumbria", "derbyshire", "devon-and-cornwall", "dorset", "durham", "dyfed-powys", "essex", "gloucestershire", "gwent", "hampshire", "hertfordshire", "humberside", "kent", "lancashire", "leicestershire", "lincolnshire", "merseyside", "metropolitan", "norfolk", "north-wales", "north-yorkshire", "northamptonshire", "northumbria", "nottinghamshire", "south-wales", "south-yorkshire", "staffordshire", "suffolk", "surrey", "sussex", "thames-valley", "warwickshire", "west-mercia", "west-midlands", "west-yorkshire", "wiltshire", "2022-01", "avon-and-somerset", "bedfordshire", "btp", "cambridgeshire", "city-of-london", "cleveland", "cumbria", "derbyshire", "devon-and-cornwall", "dorset", "durham", "dyfed-powys", "essex", "gloucestershire", "gwent", "hampshire", "hertfordshire", "humberside", "kent", "lancashire", "leicestershire", "lincolnshire", "merseyside", "metropolitan", "norfolk", "north-wales", "north-yorkshire", "northamptonshire", "northumbria", "nottinghamshire", "south-wales", "south-yorkshire", "staffordshire", "suffolk", "surrey", "sussex", "thames-valley", "warwickshire", "west-mercia", "west-midlands", "west-yorkshire", "wiltshire", "2021-12", "avon-and-somerset", "bedfordshire", "btp", "cambridgeshire", "city-of-london", "cleveland", "cumbria", "derbyshire", "devon-and-cornwall", "dorset", "durham", "dyfed-powys", "essex", "gloucestershire", "gwent", "hampshire", "hertfordshire", "humberside", "kent", "lancashire", "leicestershire", "lincolnshire", "merseyside", "metropolitan", "norfolk", "north-wales", "north-yorkshire", "northamptonshire", "northumbria", "nottinghamshire", "south-wales", "south-yorkshire", "staffordshire", "suffolk", "surrey", "sussex", "thames-valley", "warwickshire", "west-mercia", "west-midlands", "west-yorkshire", "wiltshire", "2021-11", "avon-and-somerset", "bedfordshire", "btp", "cambridgeshire", "city-of-london", "cleveland", "cumbria", "derbyshire", "devon-and-cornwall", "dorset", "durham", "dyfed-powys", "essex", "gloucestershire", "gwent", "hampshire", "hertfordshire", "humberside", "kent", "lancashire", "leicestershire", "lincolnshire", "merseyside", "metropolitan", "norfolk", "north-wales", "north-yorkshire", "northamptonshire", "northumbria", "nottinghamshire", "south-wales", "south-yorkshire", "staffordshire", "suffolk", "surrey", "sussex", "thames-valley", "warwickshire", "west-mercia", "west-midlands", "west-yorkshire", "wiltshire", "2021-10", "avon-and-somerset", "bedfordshire", "btp", "cambridgeshire", "cheshire", "city-of-london", "cleveland", "cumbria", "derbyshire", "devon-and-cornwall", "dorset", "durham", "dyfed-powys", "essex", "gloucestershire", "gwent", "hampshire", "hertfordshire", "humberside", "kent", "lancashire", "leicestershire", "lincolnshire", "merseyside", "metropolitan", "norfolk", "north-wales", "north-yorkshire", "northamptonshire", "northumbria", "nottinghamshire", "south-wales", "south-yorkshire", "staffordshire", "suffolk", "surrey", "sussex", "thames-valley", "warwickshire", "west-mercia", "west-midlands", "west-yorkshire", "wiltshire", "2021-09", "avon-and-somerset", "bedfordshire", "btp", "cambridgeshire", "cheshire", "city-of-london", "cleveland", "cumbria", "derbyshire", "devon-and-cornwall", "dorset", "durham", "dyfed-powys", "essex", "gloucestershire", "gwent", "hampshire", "hertfordshire", "humberside", "kent", "lancashire", "leicestershire", "lincolnshire", "merseyside", "metropolitan", "norfolk", "north-wales", "north-yorkshire", "northamptonshire", "northumbria", "nottinghamshire", "south-wales", "south-yorkshire", "staffordshire", "suffolk", "surrey", "sussex", "thames-valley", "warwickshire", "west-mercia", "west-midlands", "west-yorkshire", "wiltshire", "2021-08", "avon-and-somerset", "bedfordshire", "btp", "cambridgeshire", "cheshire", "city-of-london", "cleveland", "cumbria", "derbyshire", "devon-and-cornwall", "dorset", "durham", "dyfed-powys", "essex", "gloucestershire", "gwent", "hampshire", "hertfordshire", "humberside", "kent", "lancashire", "leicestershire", "lincolnshire", "merseyside", "metropolitan", "norfolk", "north-wales", "north-yorkshire", "northamptonshire", "northumbria", "nottinghamshire", "south-wales", "south-yorkshire", "staffordshire", "suffolk", "surrey", "sussex", "thames-valley", "warwickshire", "west-mercia", "west-midlands", "west-yorkshire", "wiltshire", "2021-07", "avon-and-somerset", "bedfordshire", "btp", "cambridgeshire", "cheshire", "city-of-london", "cleveland", "cumbria", "derbyshire", "devon-and-cornwall", "dorset", "durham", "dyfed-powys", "essex", "gloucestershire", "gwent", "hampshire", "hertfordshire", "humberside", "kent", "lancashire", "leicestershire", "lincolnshire", "merseyside", "metropolitan", "norfolk", "north-wales", "north-yorkshire", "northamptonshire", "northumbria", "nottinghamshire", "south-wales", "south-yorkshire", "staffordshire", "suffolk", "surrey", "sussex", "thames-valley", "warwickshire", "west-mercia", "west-midlands", "west-yorkshire", "wiltshire", "2021-06", "avon-and-somerset", "bedfordshire", "btp", "cambridgeshire", "cheshire", "city-of-london", "cleveland", "cumbria", "derbyshire", "devon-and-cornwall", "dorset", "durham", "dyfed-powys", "essex", "gloucestershire", "gwent", "hampshire", "hertfordshire", "humberside", "kent", "lancashire", "leicestershire", "lincolnshire", "merseyside", "metropolitan", "norfolk", "north-wales", "north-yorkshire", "northamptonshire", "northumbria", "nottinghamshire", "south-wales", "south-yorkshire", "staffordshire", "suffolk", "surrey", "sussex", "thames-valley", "warwickshire", "west-mercia", "west-midlands", "west-yorkshire", "wiltshire", "2021-05", "avon-and-somerset", "bedfordshire", "btp", "cambridgeshire", "cheshire", "city-of-london", "cleveland", "cumbria", "derbyshire", "devon-and-cornwall", "dorset", "durham", "dyfed-powys", "essex", "gloucestershire", "gwent", "hampshire", "hertfordshire", "humberside", "kent", "lancashire", "leicestershire", "lincolnshire", "merseyside", "metropolitan", "norfolk", "north-wales", "north-yorkshire", "northamptonshire", "northumbria", "nottinghamshire", "south-wales", "south-yorkshire", "staffordshire", "suffolk", "surrey", "sussex", "thames-valley", "warwickshire", "west-mercia", "west-midlands", "west-yorkshire", "wiltshire", "2021-04", "avon-and-somerset", "bedfordshire", "btp", "cambridgeshire", "cheshire", "city-of-london", "cleveland", "cumbria", "derbyshire", "devon-and-cornwall", "dorset", "durham", "dyfed-powys", "essex", "gloucestershire", "gwent", "hampshire", "hertfordshire", "humberside", "kent", "lancashire", "leicestershire", "lincolnshire", "merseyside", "metropolitan", "norfolk", "north-wales", "north-yorkshire", "northamptonshire", "northumbria", "nottinghamshire", "south-wales", "south-yorkshire", "staffordshire", "suffolk", "surrey", "sussex", "thames-valley", "warwickshire", "west-mercia", "west-midlands", "west-yorkshire", "wiltshire", "2021-03", "avon-and-somerset", "bedfordshire", "btp", "cambridgeshire", "cheshire", "city-of-london", "cleveland", "cumbria", "derbyshire", "devon-and-cornwall", "dorset", "durham", "dyfed-powys", "essex", "gloucestershire", "gwent", "hampshire", "hertfordshire", "humberside", "kent", "lancashire", "leicestershire", "lincolnshire", "merseyside", "metropolitan", "norfolk", "north-wales", "north-yorkshire", "northamptonshire", "northumbria", "nottinghamshire", "south-wales", "south-yorkshire", "staffordshire", "suffolk", "surrey", "sussex", "thames-valley", "warwickshire", "west-mercia", "west-midlands", "west-yorkshire", "wiltshire", "2021-02", "avon-and-somerset", "bedfordshire", "btp", "cambridgeshire", "cheshire", "city-of-london", "cleveland", "cumbria", "derbyshire", "devon-and-cornwall", "dorset", "durham", "dyfed-powys", "essex", "gloucestershire", "gwent", "hampshire", "hertfordshire", "humberside", "kent", "lancashire", "leicestershire", "lincolnshire", "merseyside", "metropolitan", "norfolk", "north-wales", "north-yorkshire", "northamptonshire", "northumbria", "nottinghamshire", "south-wales", "south-yorkshire", "staffordshire", "suffolk", "surrey", "sussex", "thames-valley", "warwickshire", "west-mercia", "west-midlands", "west-yorkshire", "wiltshire", "2021-01", "avon-and-somerset", "bedfordshire", "btp", "cambridgeshire", "cheshire", "city-of-london", "cleveland", "cumbria", "derbyshire", "devon-and-cornwall", "dorset", "durham", "dyfed-powys", "essex", "gloucestershire", "gwent", "hampshire", "hertfordshire", "humberside", "kent", "lancashire", "leicestershire", "lincolnshire", "merseyside", "metropolitan", "norfolk", "north-wales", "north-yorkshire", "northamptonshire", "northumbria", "nottinghamshire", "south-wales", "south-yorkshire", "staffordshire", "suffolk", "surrey", "sussex", "thames-valley", "warwickshire", "west-mercia", "west-midlands", "west-yorkshire", "wiltshire", "2020-12", "avon-and-somerset", "bedfordshire", "btp", "cambridgeshire", "cheshire", "city-of-london", "cleveland", "cumbria", "derbyshire", "devon-and-cornwall", "dorset", "durham", "dyfed-powys", "essex", "gloucestershire", "gwent", "hampshire", "hertfordshire", "humberside", "kent", "lancashire", "leicestershire", "lincolnshire", "merseyside", "metropolitan", "norfolk", "north-wales", "north-yorkshire", "northamptonshire", "northumbria", "nottinghamshire", "south-wales", "south-yorkshire", "staffordshire", "suffolk", "surrey", "sussex", "thames-valley", "warwickshire", "west-mercia", "west-midlands", "west-yorkshire", "wiltshire", "2020-11", "avon-and-somerset", "bedfordshire", "btp", "cambridgeshire", "cheshire", "city-of-london", "cleveland", "cumbria", "derbyshire", "devon-and-cornwall", "dorset", "durham", "dyfed-powys", "essex", "gloucestershire", "gwent", "hampshire", "hertfordshire", "humberside", "kent", "lancashire", "leicestershire", "lincolnshire", "merseyside", "metropolitan", "norfolk", "north-wales", "north-yorkshire", "northamptonshire", "northumbria", "nottinghamshire", "south-wales", "south-yorkshire", "staffordshire", "suffolk", "surrey", "sussex", "thames-valley", "warwickshire", "west-mercia", "west-midlands", "west-yorkshire", "wiltshire", "2020-10", "avon-and-somerset", "bedfordshire", "btp", "cambridgeshire", "cheshire", "city-of-london", "cleveland", "cumbria", "derbyshire", "devon-and-cornwall", "dorset", "durham", "dyfed-powys", "essex", "gloucestershire", "gwent", "hampshire", "hertfordshire", "humberside", "kent", "lancashire", "leicestershire", "lincolnshire", "merseyside", "metropolitan", "norfolk", "north-wales", "north-yorkshire", "northamptonshire", "northumbria", "nottinghamshire", "south-wales", "south-yorkshire", "staffordshire", "suffolk", "surrey", "sussex", "thames-valley", "warwickshire", "west-mercia", "west-midlands", "west-yorkshire", "wiltshire", "2020-09", "avon-and-somerset", "bedfordshire", "btp", "cambridgeshire", "cheshire", "city-of-london", "cleveland", "cumbria", "derbyshire", "devon-and-cornwall", "dorset", "durham", "dyfed-powys", "essex", "gloucestershire", "gwent", "hampshire", "hertfordshire", "humberside", "kent", "lancashire", "leicestershire", "lincolnshire", "merseyside", "metropolitan", "norfolk", "north-wales", "north-yorkshire", "northamptonshire", "northumbria", "nottinghamshire", "south-wales", "south-yorkshire", "staffordshire", "suffolk", "surrey", "sussex", "thames-valley", "warwickshire", "west-mercia", "west-midlands", "west-yorkshire", "wiltshire", "2020-08", "avon-and-somerset", "bedfordshire", "btp", "cambridgeshire", "cheshire", "city-of-london", "cleveland", "cumbria", "derbyshire", "devon-and-cornwall", "dorset", "durham", "dyfed-powys", "essex", "gloucestershire", "gwent", "hampshire", "hertfordshire", "humberside", "kent", "lancashire", "leicestershire", "lincolnshire", "merseyside", "metropolitan", "norfolk", "north-wales", "north-yorkshire", "northamptonshire", "northumbria", "nottinghamshire", "south-wales", "south-yorkshire", "staffordshire", "suffolk", "surrey", "sussex", "thames-valley", "warwickshire", "west-mercia", "west-midlands", "west-yorkshire", "wiltshire", "2020-07", "avon-and-somerset", "bedfordshire", "btp", "cambridgeshire", "cheshire", "city-of-london", "cleveland", "cumbria", "derbyshire", "devon-and-cornwall", "dorset", "durham", "dyfed-powys", "essex", "gloucestershire", "gwent", "hampshire", "hertfordshire", "humberside", "kent", "lancashire", "leicestershire", "lincolnshire", "merseyside", "metropolitan", "norfolk", "north-wales", "north-yorkshire", "northamptonshire", "northumbria", "nottinghamshire", "south-wales", "south-yorkshire", "staffordshire", "suffolk", "surrey", "sussex", "thames-valley", "warwickshire", "west-mercia", "west-midlands", "west-yorkshire", "wiltshire", "2020-06", "avon-and-somerset", "bedfordshire", "btp", "cambridgeshire", "cheshire", "city-of-london", "cleveland", "cumbria", "derbyshire", "devon-and-cornwall", "dorset", "durham", "dyfed-powys", "essex", "gloucestershire", "gwent", "hampshire", "hertfordshire", "humberside", "kent", "lancashire", "leicestershire", "lincolnshire", "merseyside", "metropolitan", "norfolk", "north-wales", "north-yorkshire", "northamptonshire", "northumbria", "nottinghamshire", "south-wales", "south-yorkshire", "staffordshire", "suffolk", "surrey", "sussex", "thames-valley", "warwickshire", "west-mercia", "west-midlands", "west-yorkshire", "wiltshire", "2020-05", "avon-and-somerset", "bedfordshire", "btp", "cambridgeshire", "cheshire", "city-of-london", "cleveland", "cumbria", "derbyshire", "devon-and-cornwall", "dorset", "durham", "dyfed-powys", "essex", "gloucestershire", "gwent", "hampshire", "hertfordshire", "humberside", "kent", "lancashire", "leicestershire", "lincolnshire", "merseyside", "metropolitan", "norfolk", "north-wales", "north-yorkshire", "northamptonshire", "northumbria", "nottinghamshire", "south-wales", "south-yorkshire", "staffordshire", "suffolk", "surrey", "sussex", "thames-valley", "warwickshire", "west-mercia", "west-midlands", "west-yorkshire", "wiltshire", "2020-04", "avon-and-somerset", "bedfordshire", "btp", "cambridgeshire", "cheshire", "city-of-london", "cleveland", "cumbria", "derbyshire", "devon-and-cornwall", "dorset", "durham", "dyfed-powys", "essex", "gloucestershire", "gwent", "hampshire", "hertfordshire", "humberside", "kent", "lancashire", "leicestershire", "lincolnshire", "merseyside", "metropolitan", "norfolk", "north-wales", "north-yorkshire", "northamptonshire", "northumbria", "nottinghamshire", "south-wales", "south-yorkshire", "staffordshire", "suffolk", "surrey", "sussex", "thames-valley", "warwickshire", "west-mercia", "west-midlands", "west-yorkshire", "wiltshire", "2020-03", "avon-and-somerset", "bedfordshire", "btp", "cambridgeshire", "cheshire", "city-of-london", "cleveland", "cumbria", "derbyshire", "devon-and-cornwall", "dorset", "durham", "dyfed-powys", "essex", "gloucestershire", "gwent", "hampshire", "hertfordshire", "humberside", "kent", "lancashire", "leicestershire", "lincolnshire", "merseyside", "metropolitan", "norfolk", "north-wales", "north-yorkshire", "northamptonshire", "northumbria", "nottinghamshire", "south-wales", "south-yorkshire", "staffordshire", "suffolk", "surrey", "sussex", "thames-valley", "warwickshire", "west-mercia", "west-midlands", "west-yorkshire", "wiltshire", "2020-02", "avon-and-somerset", "bedfordshire", "btp", "cambridgeshire", "cheshire", "city-of-london", "cleveland", "cumbria", "derbyshire", "devon-and-cornwall", "dorset", "durham", "dyfed-powys", "essex", "gloucestershire", "gwent", "hampshire", "hertfordshire", "humberside", "kent", "lancashire", "leicestershire", "lincolnshire", "merseyside", "metropolitan", "norfolk", "north-wales", "north-yorkshire", "northamptonshire", "northumbria", "nottinghamshire", "south-wales", "south-yorkshire", "staffordshire", "suffolk", "surrey", "sussex", "thames-valley", "warwickshire", "west-mercia", "west-midlands", "west-yorkshire", "wiltshire", "2020-01", "avon-and-somerset", "bedfordshire", "btp", "cambridgeshire", "cheshire", "city-of-london", "cleveland", "cumbria", "derbyshire", "devon-and-cornwall", "dorset", "durham", "dyfed-powys", "essex", "gloucestershire", "gwent", "hampshire", "hertfordshire", "humberside", "kent", "lancashire", "leicestershire", "lincolnshire", "merseyside", "metropolitan", "norfolk", "north-wales", "north-yorkshire", "northamptonshire", "northumbria", "nottinghamshire", "south-wales", "south-yorkshire", "staffordshire", "suffolk", "surrey", "sussex", "thames-valley", "warwickshire", "west-mercia", "west-midlands", "west-yorkshire", "wiltshire"]

    freq = EnumLruMapping(256, 3)
    for key in data:
        index = freq.add(key)
        if index is not None:
            print(index, key)
    print('bang', freq._index_map)
    #print('bang', freq._lru)
    #print('bang', freq._lru_map)
