1.1 --- a/iixr/data.py Sat Feb 12 01:23:58 2011 +0100
1.2 +++ b/iixr/data.py Sun Feb 13 02:49:55 2011 +0100
1.3 @@ -23,7 +23,7 @@
1.4
1.5 # High-level representations.
1.6
1.7 -def convert_sequence(values, op):
1.8 +def convert_sequence(values, op, last_from_old):
1.9 if values:
1.10 new_values = list(values)
1.11 last = new_values[0]
1.12 @@ -31,10 +31,22 @@
1.13 length = len(new_values)
1.14 while i < length:
1.15 current = new_values[i]
1.16 - new_values[i] = op(new_values[i], last)
1.17 - last = current
1.18 + new_values[i] = op(current, last)
1.19 +
1.20 + # Subtracting entries requires the old value to be used.
1.21 + # Adding entries requires the new value.
1.22 +
1.23 + if last_from_old:
1.24 + last = current
1.25 + else:
1.26 + last = new_values[i]
1.27 +
1.28 i += 1
1.29
1.30 + return new_values
1.31 + else:
1.32 + return values
1.33 +
1.34 def op_seq_monotonic(x, y, op):
1.35 return tuple([op(a, b) for a, b in zip(x, y)])
1.36
1.37 @@ -44,15 +56,6 @@
1.38 def sub_seq_monotonic(x, y):
1.39 return op_seq_monotonic(x, y, operator.sub)
1.40
1.41 -def op_first_monotonic(x, y, op):
1.42 - return (op(x[0], y[0]),) + tuple(zip(x[1:], y[1:]))
1.43 -
1.44 -def add_first_monotonic(x, y):
1.45 - return op_first_monotonic(x, y, operator.add)
1.46 -
1.47 -def sub_first_monotonic(x, y):
1.48 - return op_first_monotonic(x, y, operator.sub)
1.49 -
1.50 def add_seq(x, y):
1.51 length = min(len(x), len(y))
1.52 seq = list(x)[:length]
1.53 @@ -84,17 +87,17 @@
1.54 def sizeof(value):
1.55 return is_sequence(value) and len(value) or 0
1.56
1.57 -def get_monotonic_adder(value):
1.58 - return is_sequence(value) and add_seq_monotonic or operator.add
1.59 +def get_monotonic_adder(size):
1.60 + return size and add_seq_monotonic or operator.add
1.61
1.62 -def get_monotonic_subtractor(value):
1.63 - return is_sequence(value) and sub_seq_monotonic or operator.sub
1.64 +def get_monotonic_subtractor(size):
1.65 + return size and sub_seq_monotonic or operator.sub
1.66
1.67 -def get_adder(value):
1.68 - return is_sequence(value) and add_seq or operator.add
1.69 +def get_adder(size):
1.70 + return size and add_seq or operator.add
1.71
1.72 -def get_subtractor(value):
1.73 - return is_sequence(value) and sub_seq or operator.sub
1.74 +def get_subtractor(size):
1.75 + return size and sub_seq or operator.sub
1.76
1.77 # Low-level representations.
1.78 # Variable-length integer functions.
1.79 @@ -177,15 +180,6 @@
1.80 break
1.81 return number, start
1.82
1.83 -# String serialisation.
1.84 -
1.85 -def string_to_array(s, bytes):
1.86 -
1.87 - "Write the given string 's' to 'bytes'."
1.88 -
1.89 - vint_to_array(len(s), bytes)
1.90 - bytes.fromstring(s.encode("utf-8"))
1.91 -
1.92 # Sequence serialisation.
1.93
1.94 def sequence_to_array(value, size, bytes):