source: trunk/symbol_table/div2_group_strms.py @ 2065

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

Added in log2 pablo statements. Updated Python demo.

File size: 2.1 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        shift_or_ends = (groups.ends | pablo.Advance(groups.ends))
20        ends = groups.ends
21
22        # Group symbols of length 1 and length 2
23        cursor = pablo.Advance(pablo.Advance(groups.starts))
24        groups.ends_2 = cursor & (shift_or_ends)
25
26        mask = pablo.Advance(groups.starts) | pablo.Advance(pablo.Advance(groups.starts))
27        ends = ends &~ mask
28
29        # Group symbols of length 3 and length 4
30        cursor = pablo.Advance(pablo.Advance(cursor &~ shift_or_ends))
31        groups.ends_4 = cursor & (shift_or_ends)
32
33        mask = pablo.Advance(pablo.Advance(mask))
34        ends = ends &~ mask
35
36        ## Group symbols of length 5 and length 6
37        cursor = pablo.Advance(pablo.Advance(cursor &~ shift_or_ends))
38        groups.ends_6 = cursor & (shift_or_ends)
39
40        mask = pablo.Advance(pablo.Advance(mask))
41        ends = ends &~ mask
42
43        ## Group symbols of length 7 and length 8
44        cursor = pablo.Advance(pablo.Advance(cursor &~ shift_or_ends))
45        groups.ends_8 = cursor & (shift_or_ends)
46
47        mask = pablo.Advance(pablo.Advance(mask))
48        ends = ends &~ mask
49
50        ## Group symbols of length 9 and length 10
51        cursor = pablo.Advance(pablo.Advance(cursor &~ shift_or_ends))
52        groups.ends_10 = cursor & (shift_or_ends)
53
54        mask = pablo.Advance(pablo.Advance(mask))
55        ends = ends &~ mask
56
57        ## Group symbols of length 11 and length 12
58        cursor = pablo.Advance(pablo.Advance(cursor &~ shift_or_ends))
59        groups.ends_12 = cursor & (shift_or_ends)
60
61        mask = pablo.Advance(pablo.Advance(mask))
62        ends = ends &~ mask
63
64        ## Group symbols of length 13 and length 14
65        cursor = pablo.Advance(pablo.Advance(cursor &~ shift_or_ends))
66        groups.ends_14 = cursor & (shift_or_ends)
67
68        mask = pablo.Advance(pablo.Advance(mask))
69        ends = ends &~ mask
70
71        ## Group symbols of length 15 and length 16
72        cursor = pablo.Advance(pablo.Advance(cursor &~ shift_or_ends))
73        groups.ends_16 = cursor & (shift_or_ends)
74
75        mask = pablo.Advance(pablo.Advance(mask))
76        ends = ends &~ mask
77
78        ## Group symbols of length greater than equal to 17
79        groups.ends_gte_17 = ends
80
81def Main(groups):
82        Gen_lgth_groups(groups)
Note: See TracBrowser for help on using the repository browser.