77 lines
2.6 KiB
Python
77 lines
2.6 KiB
Python
#
|
|
# Sam Hadow - Huffman-py
|
|
# Copyright (C) 2023
|
|
#
|
|
# This program 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.
|
|
#
|
|
# 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 <http://www.gnu.org/licenses/>.
|
|
#
|
|
|
|
class Node(object):
|
|
def __init__(self, occurrence, char, left = None, right = None):
|
|
# nombre d'occurence de la lettre
|
|
self.occurrence = occurrence
|
|
|
|
# the character
|
|
self.char = char
|
|
|
|
# left child
|
|
self.left = left
|
|
|
|
# right child
|
|
self.right = right
|
|
|
|
# orientation from father (0: left, 1: right)
|
|
self.code = ''
|
|
|
|
# node identifier (unique in a tree)
|
|
self.identifier = None
|
|
|
|
|
|
# getters and setters (private attributes)
|
|
|
|
def get_occurence(self):
|
|
return self.__occurence
|
|
def set_occurence(self, valeur):
|
|
self.__occurence = valeur
|
|
occurence = property(fget=get_occurence, fset=set_occurence, doc="Character occurences in a text")
|
|
|
|
def get_char(self):
|
|
return self.__char
|
|
def set_char(self, valeur):
|
|
self.__char = valeur
|
|
char = property(fget=get_char, fset=set_char, doc="corresponding character")
|
|
|
|
def get_left(self):
|
|
return self.__left
|
|
def set_left(self, valeur):
|
|
self.__left = valeur
|
|
left = property(fget=get_left, fset=set_left, doc="left child")
|
|
|
|
def get_right(self):
|
|
return self.__right
|
|
def set_right(self, valeur):
|
|
self.__right = valeur
|
|
right = property(fget=get_right, fset=set_right, doc="right child")
|
|
|
|
def get_code(self):
|
|
return self.__code
|
|
def set_code(self, valeur):
|
|
self.__code = valeur
|
|
code = property(fget=get_code, fset=set_code, doc="orientation from father (0: left, 1: right)")
|
|
|
|
def get_id(self):
|
|
return self.__identifier
|
|
def set_id(self, valeur):
|
|
self.__identifier = valeur
|
|
identifier = property(fget=get_id, fset=set_id, doc="node identifier")
|