X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=src%2Fnepi%2Futil%2Fguid.py;h=45852118cc65036c978169c099cf909ede1249e0;hb=a62ad48360778748ee3d5ba65b14ea6eeb27c032;hp=7f5ea3cf05fe31f65e928ecc75b97c69cb6c5781;hpb=431d85b5200b64fe9f960104da480258f8f5d7b1;p=nepi.git diff --git a/src/nepi/util/guid.py b/src/nepi/util/guid.py index 7f5ea3cf..45852118 100644 --- a/src/nepi/util/guid.py +++ b/src/nepi/util/guid.py @@ -1,17 +1,33 @@ -# -*- coding: utf-8 -*- +# +# NEPI, a framework to manage network experiments +# Copyright (C) 2013 INRIA +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 2 as +# published by the Free Software Foundation; +# +# This program 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 this program. If not, see . +# +# Author: Alina Quereilhac +# FIXME: This class is not thread-safe. +# Should it be made thread-safe? class GuidGenerator(object): def __init__(self): - self._guids = list() + self._last_guid = 0 + # xxx_next_hiccup - this is used as a plain function, and only in ec.py def next(self, guid = None): - if guid != None: - if guid in self._guids: - raise RuntimeError("guid %d is already assigned" % guid) - else: - last_guid = 0 if len(self._guids) == 0 else self._guids[-1] - guid = last_guid + 1 - self._guids.append(guid) - self._guids.sort() + if guid == None: + guid = self._last_guid + 1 + + self._last_guid = self._last_guid if guid <= self._last_guid else guid + return guid