cengal.data_containers.limitable_dict_with_order.versions.v_0.limitable_dict_with_order
Module Docstring Docstrings: http://www.python.org/dev/peps/pep-0257/
1#!/usr/bin/env python 2# coding=utf-8 3 4# Copyright © 2012-2024 ButenkoMS. All rights reserved. Contacts: <gtalk@butenkoms.space> 5# 6# Licensed under the Apache License, Version 2.0 (the "License"); 7# you may not use this file except in compliance with the License. 8# You may obtain a copy of the License at 9# 10# http://www.apache.org/licenses/LICENSE-2.0 11# 12# Unless required by applicable law or agreed to in writing, software 13# distributed under the License is distributed on an "AS IS" BASIS, 14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15# See the License for the specific language governing permissions and 16# limitations under the License. 17 18""" 19Module Docstring 20Docstrings: http://www.python.org/dev/peps/pep-0257/ 21""" 22 23__author__ = "ButenkoMS <gtalk@butenkoms.space>" 24__copyright__ = "Copyright © 2012-2024 ButenkoMS. All rights reserved. Contacts: <gtalk@butenkoms.space>" 25__credits__ = ["ButenkoMS <gtalk@butenkoms.space>", ] 26__license__ = "Apache License, Version 2.0" 27__version__ = "4.4.1" 28__maintainer__ = "ButenkoMS <gtalk@butenkoms.space>" 29__email__ = "gtalk@butenkoms.space" 30# __status__ = "Prototype" 31__status__ = "Development" 32# __status__ = "Production" 33 34 35from cengal.code_flow_control.none_or import none_or 36from typing import Dict, List, Optional 37 38 39class LimitableDictWithOrder: 40 def __init__(self, low_water: int, hi_water: int, data: Optional[Dict] = None, order: Optional[List] = None) -> None: 41 self.low_water: int = low_water if low_water >= 0 else 0 42 self.hi_water: int = hi_water if hi_water >= 0 else 0 43 self.data: Optional[Dict] = none_or(data, dict()) 44 self.order: Optional[List] = none_or(order, list()) 45 46 def check_limits(self): 47 if len(self.order) <= self.hi_water: 48 return 49 50 keys_to_delete = self.order[:-self.low_water] 51 self.order = self.order[-self.low_water:] 52 for key in keys_to_delete: 53 self.data.pop(key, None) 54 55 def __call__(self): 56 return self.check_limits()
class
LimitableDictWithOrder:
40class LimitableDictWithOrder: 41 def __init__(self, low_water: int, hi_water: int, data: Optional[Dict] = None, order: Optional[List] = None) -> None: 42 self.low_water: int = low_water if low_water >= 0 else 0 43 self.hi_water: int = hi_water if hi_water >= 0 else 0 44 self.data: Optional[Dict] = none_or(data, dict()) 45 self.order: Optional[List] = none_or(order, list()) 46 47 def check_limits(self): 48 if len(self.order) <= self.hi_water: 49 return 50 51 keys_to_delete = self.order[:-self.low_water] 52 self.order = self.order[-self.low_water:] 53 for key in keys_to_delete: 54 self.data.pop(key, None) 55 56 def __call__(self): 57 return self.check_limits()
LimitableDictWithOrder( low_water: int, hi_water: int, data: Union[Dict, NoneType] = None, order: Union[List, NoneType] = None)
41 def __init__(self, low_water: int, hi_water: int, data: Optional[Dict] = None, order: Optional[List] = None) -> None: 42 self.low_water: int = low_water if low_water >= 0 else 0 43 self.hi_water: int = hi_water if hi_water >= 0 else 0 44 self.data: Optional[Dict] = none_or(data, dict()) 45 self.order: Optional[List] = none_or(order, list())