Ejemplo n.º 1
0
 def updatePackets(self, packet: Packet) -> bool:
     if (packet.get_degree() == 1 and
             next(iter(packet.get_used_packets())) < self.number_of_chunks
             and (next(iter(packet.get_used_packets())) != 0
                  or not self.use_headerchunk)):
         # Directly add Packets that are degree == 1 (except for HeaderPacket)
         self.decodedPackets.add(packet)
         return self.is_decoded()
     self.queue.append(packet)
     self.solve()
Ejemplo n.º 2
0
 def compareAndReduce(self, packet: Packet, other: Packet) -> typing.Union[bool, int]:
     if self.file is None:  # In case of PseudoDecode: DO NOT REALLY COMPUTE XOR
         packet.remove_packets(other.get_used_packets())
     else:
         packet.xor_and_remove_packet(other)
     degree = packet.get_degree()
     if (degree not in self.degreeToPacket) or (not isinstance(self.degreeToPacket[degree], set)):
         self.degreeToPacket[degree] = set()
     self.degreeToPacket[degree].add(packet)
     if self.is_decoded():
         return True
     self.queue.append(packet)
     return degree
Ejemplo n.º 3
0
 def reduceAll(self, packet: Packet) -> bool:
     # lookup all packets for this to solve with ( when this packet has a subset of used Packets)
     fin: bool = False
     lookup: typing.List[int] = [
         i for i in self.degreeToPacket.keys() if packet.get_degree() < i
     ]
     for i in lookup:
         if not isinstance(self.degreeToPacket[i], set):
             self.degreeToPacket[i] = set()
         for p in self.degreeToPacket[i].copy():
             p_used = p.get_used_packets()
             pack_used = packet.get_used_packets()
             if len(pack_used) < len(p_used) and pack_used.issubset(p_used):
                 self.degreeToPacket[i].remove(p)
                 degree = self.compareAndReduce(p, packet)
                 if isinstance(degree, bool) and degree is True:
                     return degree
     degree: int = packet.get_degree()
     lookup: typing.List[int] = [
         i for i in self.degreeToPacket.keys() if packet.get_degree() > i
     ]
     for i in lookup:
         if not isinstance(self.degreeToPacket[i], set):
             self.degreeToPacket[i] = set()
         for p in self.degreeToPacket[i].copy():
             p_used = p.get_used_packets()
             pack_used = packet.get_used_packets()
             if len(pack_used) > len(p_used) and p_used.issubset(pack_used):
                 try:
                     self.degreeToPacket[degree].remove(packet)
                     degree = self.compareAndReduce(packet, p)
                     if isinstance(degree, bool) and degree is True:
                         return degree
                 except:
                     continue
                 # If we already reduced a Packet with the same used_packets, there is no need to do it again
     return fin or self.is_decoded()
Ejemplo n.º 4
0
 def compareAndReduce(self, packet: Packet,
                      other: Packet) -> typing.Union[bool, int]:
     if self.file is None:
         packet.remove_packets(other.get_used_packets())
     else:
         packet.xor_and_remove_packet(other)
     degree = packet.get_degree()
     if (degree not in self.degreeToPacket) or (not isinstance(
             self.degreeToPacket[degree], set)):
         self.degreeToPacket[degree] = set()
     if degree == 1:
         [x] = (packet.get_used_packets()
                )  # Unpacking -> Fastest way to extract Element from Set
         if x > self.number_of_chunks:  # we got a new AUX-Packet
             raise RuntimeError("this should not have happened!")
         else:
             if x != 0 or not self.use_headerchunk:
                 self.decodedPackets.add(
                     packet)  # Add Packet to decoded Packets
     self.degreeToPacket[degree].add(packet)
     if self.is_decoded():
         return True
     self.queue.append(packet)
     return degree
Ejemplo n.º 5
0
 def addPacket(self, packet: Packet) -> None:
     if (packet.get_degree() not in self.degreeToPacket) or (
             not isinstance(self.degreeToPacket[packet.get_degree()], set)):
         self.degreeToPacket[packet.get_degree()] = set()
     self.number_of_chunks = packet.get_total_number_of_chunks()
     self.degreeToPacket[packet.get_degree()].add(packet)