46 lines
1.3 KiB
Python
46 lines
1.3 KiB
Python
# Copyright (C) 2024 Michael Becker <alcexhim@gmail.com>
|
|
#
|
|
# This file is part of yaml2mcl.
|
|
#
|
|
# yaml2mcl is free software: you can redistribute it and/or modify
|
|
# it under the terms of the GNU General Public License as published by
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
# (at your option) any later version.
|
|
#
|
|
# yaml2mcl is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU General Public License
|
|
# along with yaml2mcl. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
from framework import Guid
|
|
|
|
class GuidCache:
|
|
|
|
def __init__(self):
|
|
self.guid_db = dict()
|
|
self.indx_db = dict()
|
|
self.__index = 0
|
|
|
|
def add(self, guid : Guid):
|
|
if not guid in self.indx_db:
|
|
self.guid_db[self.__index] = guid
|
|
self.indx_db[guid] = self.__index
|
|
self.__index += 1
|
|
|
|
def count(self):
|
|
return len(self.indx_db)
|
|
|
|
def get_guid(self, index : int) -> Guid:
|
|
return self.guid_db[index]
|
|
|
|
def get_index(self, guid : Guid) -> int:
|
|
return self.indx_db[guid]
|
|
|
|
def to_list(self) -> list:
|
|
ls = [ ]
|
|
for i in range(0, self.count()):
|
|
ls.append(self.get_guid(i))
|
|
return ls |