load a list of n_bit words
(self, value_lst)
| 39 | return u.getvalue() |
| 40 | |
| 41 | def load_data(self, value_lst) : |
| 42 | """ load a list of n_bit words """ |
| 43 | w_curs = 0 # position in the word |
| 44 | word = 0 |
| 45 | stack = list() |
| 46 | for n, value in enumerate(value_lst) : |
| 47 | value = value & self.b_mask |
| 48 | v_curs = 0 # position in the value |
| 49 | v_count = self.n_bit - v_curs # number of remaining bits to be written |
| 50 | w_count = self.m - w_curs # number of bits available in the word |
| 51 | while v_count > 0 : |
| 52 | if w_count <= v_count : |
| 53 | p = value >> (v_count - w_count) |
| 54 | word |= p & self.i_mask |
| 55 | v_curs += w_count |
| 56 | w_curs += w_count |
| 57 | else : |
| 58 | p = value << (w_count - v_count) |
| 59 | word |= p & self.i_mask |
| 60 | v_curs += v_count |
| 61 | w_curs += v_count |
| 62 | if w_curs == self.m : |
| 63 | stack.append(word) |
| 64 | word = 0 |
| 65 | w_curs = 0 |
| 66 | v_count = self.n_bit - v_curs |
| 67 | w_count = self.m - w_curs |
| 68 | if word : |
| 69 | stack.append(word) |
| 70 | self.n_item = len(value_lst) |
| 71 | self._data = array.array(self.f, stack) |
| 72 | return self |
| 73 | |
| 74 | def _get_at(self, v_index) : |
| 75 | if not 0 <= v_index < self.n_item : |