예제 #1
0
class display_name_prefix(object):
    def __init__(self):
        self.next_suffix = 0
        self.holes = RBTree()

    def new_suffix(self):
        if len(self.holes) == 0:
            suffix = self.next_suffix
            self.next_suffix += 1
        else:
            first_node = self.holes.firstNode()
            suffix = first_node.key
            self.holes.deleteNode(first_node)
        return suffix

    def putback_suffix(self, suffix):
        if suffix + 1 != self.next_suffix:
            self.holes.insertNode(suffix, suffix)
            return

        self.next_suffix = suffix
        while True:
            prev_suffix = self.next_suffix - 1
            prev_suffix_node = self.holes.findNode(prev_suffix)
            if not prev_suffix_node:
                return
            self.holes.deleteNode(prev_suffix_node)
            self.next_suffix = prev_suffix

    def empty(self):
        return self.next_suffix == 0
예제 #2
0
class display_name_prefix(object):
    def __init__(self):
        self.next_suffix = 0
        self.holes = RBTree()

    def new_suffix(self):
        if len(self.holes) == 0:
            suffix = self.next_suffix
            self.next_suffix += 1
        else:
            first_node = self.holes.firstNode()
            suffix = first_node.key
            self.holes.deleteNode(first_node)
        return suffix

    def putback_suffix(self, suffix):
        if suffix + 1 != self.next_suffix:
            self.holes.insertNode(suffix, suffix)
            return

        self.next_suffix = suffix
        while True:
            prev_suffix = self.next_suffix - 1
            prev_suffix_node = self.holes.findNode(prev_suffix)
            if not prev_suffix_node:
                return
            self.holes.deleteNode(prev_suffix_node)
            self.next_suffix = prev_suffix

    def empty(self):
        return self.next_suffix == 0
예제 #3
0
 def __init__(self):
     self.next_suffix = 0
     self.holes = RBTree()
예제 #4
0
 def __init__(self):
     self.next_suffix = 0
     self.holes = RBTree()
예제 #5
0
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
# See the COPYING file for license information.
#
# Copyright (c) 2008 Guillaume Chazarain <*****@*****.**>

from polysh.rb_tree import RBTree

# {'prefix': <display_name_prefix object>}
PREFIXES = {}

# Red/black tree with key:len(display_name) value:nr of enabled shells with a
# display_name of such a length
NR_ENABLED_DISPLAY_NAMES_BY_LENGTH = RBTree()

# Cache the right most element in the NR_ENABLED_DISPLAY_NAMES_BY_LENGTH tree
max_display_name_length = 0


class display_name_prefix(object):
    def __init__(self):
        self.next_suffix = 0
        self.holes = RBTree()

    def new_suffix(self):
        if len(self.holes) == 0:
            suffix = self.next_suffix
            self.next_suffix += 1
        else: