source: trunk/symbol_table/div2_group_strms.py @ 2056

Last change on this file since 2056 was 2056, checked in by ksherdy, 7 years ago

Updated div2 to support arbitrary lengths.

File size: 1.9 KB
Line 
1# demo
2import bitutil as pablo
3
4class Groups():
5        starts = 0
6        ends = 0
7        ends_2 = 0
8        ends_4 = 0
9        ends_6 = 0
10        ends_8 = 0
11        ends_10 = 0
12        ends_12 = 0
13        ends_14 = 0
14        ends_16 = 0
15        ends_gte_17 = 0
16
17def Gen_lgth_groups(groups):
18
19        cursor = groups.starts
20        shift_or_ends = groups.ends | pablo.Advance(groups.ends)
21        temp = groups.ends
22
23        # Group symbols of length 1 and length 2
24        cursor = pablo.Advance(pablo.Advance(cursor))
25        groups.ends_2 = cursor & shift_or_ends
26        temp = temp &~ groups.ends_2
27
28        # Group symbols of length 3 and length 4
29        cursor = pablo.Advance(pablo.Advance(cursor &~ shift_or_ends))
30        groups.ends_4 = cursor & shift_or_ends
31        temp = temp &~ groups.ends_4
32
33        # Group symbols of length 5 and length 6
34        cursor = pablo.Advance(pablo.Advance(cursor &~ shift_or_ends))
35        groups.ends_6 = cursor & shift_or_ends
36        temp = temp &~ groups.ends_6
37
38        # Group symbols of length 7 and length 8
39        cursor = pablo.Advance(pablo.Advance(cursor &~ shift_or_ends))
40        groups.ends_8 = cursor & shift_or_ends
41        temp = temp &~ groups.ends_8
42
43        # Group symbols of length 9 and length 10
44        cursor = pablo.Advance(pablo.Advance(cursor &~ shift_or_ends))
45        groups.ends_10 = cursor & shift_or_ends
46        temp = temp &~ groups.ends_10
47
48        # Group symbols of length 11 and length 12
49        cursor = pablo.Advance(pablo.Advance(cursor &~ shift_or_ends))
50        groups.ends_12 = cursor & shift_or_ends
51        temp = temp &~ groups.ends_12
52
53        # Group symbols of length 13 and length 14
54        cursor = pablo.Advance(pablo.Advance(cursor &~ shift_or_ends))
55        groups.ends_14 = cursor & shift_or_ends
56        temp = temp &~ groups.ends_14
57
58        # Group symbols of length 15 and length 16
59        cursor = pablo.Advance(pablo.Advance(cursor &~ shift_or_ends))
60        groups.ends_16 = cursor & shift_or_ends
61        temp = temp &~ groups.ends_16
62
63        # Group symbols of length greater than equal to 17
64        groups.ends_gte_17 = temp
65
66def Main(groups):
67        Gen_lgth_groups(groups)
Note: See TracBrowser for help on using the repository browser.