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

Method load_data

recipes/Python/580649_nbitarray/recipe-580649.py:41–72  ·  view source on GitHub ↗

load a list of n_bit words

(self, value_lst)

Source from the content-addressed store, hash-verified

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 :

Callers 1

doFunction · 0.80

Calls 3

listClass · 0.85
enumerateFunction · 0.50
appendMethod · 0.45

Tested by

no test coverage detected