MCPcopy Create free account
hub / github.com/ActiveState/code / erase

Method erase

recipes/Python/492209_dal1py/recipe-492209.py:85–123  ·  view source on GitHub ↗
(self, index, size)

Source from the content-addressed store, hash-verified

83
84 # Erase Some Data
85 def erase(self, index, size):
86 assert type(index) is int and 0 <= index < self.__end
87 assert type(size) is int and index < index + size <= self.__end
88 first_index = index
89 last_index = index + size - 1
90 first_block = first_index / self.__size + 1
91 last_block = last_index / self.__size + 2
92 blocks = last_block - first_block
93 if blocks == 1:
94 if size == self.__size:
95 self.__erase(first_block)
96 else:
97 stream = self.__read(first_block)
98 first_index = index % self.__size
99 last_index = first_index + size
100 stream = stream[:first_index] + chr(0) * size + \
101 stream[last_index:]
102 self.__write(first_block, stream)
103 else:
104 if index % self.__size:
105 stream = self.__read(first_block)
106 first_index = index % self.__size
107 last_index = self.__size - first_index
108 stream = stream[:first_index] + chr(0) * last_index
109 self.__write(first_block, stream)
110 else:
111 self.__erase(first_block)
112 first_block += 1
113 last_block -= 1
114 for block in range(first_block, last_block):
115 self.__erase(block)
116 last_index = index + size - 1
117 size = (last_index % self.__size) + 1
118 if size == self.__size:
119 self.__erase(last_block)
120 else:
121 stream = self.__read(last_block)
122 stream = chr(0) * size + stream[size:]
123 self.__write(last_block, stream)
124
125 # Probability Of Failure
126 def fail(self, probability):

Callers 4

testFunction · 0.95
closeMethod · 0.45
__softMethod · 0.45
__eraseMethod · 0.45

Calls 4

__eraseMethod · 0.95
__readMethod · 0.95
__writeMethod · 0.95
rangeFunction · 0.85

Tested by

no test coverage detected