-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetpruningtrie.java
92 lines (78 loc) · 2.17 KB
/
setpruningtrie.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import java.util.*;
class setpruningtrie{
public static void main(String []args){
f1trieNode head = new f1trieNode();
String arr1[] = {"00*","00*","10*","0*","0*","0*","*"};
String arr2[] = {"110*","11*","1*","01*","10*","1*","00*"};
String arr3[] = {"R1","R2","R3","R4","R5","R6","R7"};
HashMap<String,HashMap<String,String>> hm = new HashMap<String,HashMap<String,String>>();
classify(arr1,arr2,arr3,hm);
createtrie(hm,head);
}
public static void classify(String arr1[], String arr2[], String arr3[], HashMap<String,HashMap<String,String>> hm){
for(int i=0;i<arr1.length;i++){
if(hm.containsKey(arr1[i])){
hm.get(arr1[i]).put(arr2[i],arr3[i]);
}
else{
HashMap<String,String> rulemap = new HashMap<String,String>();
rulemap.put(arr2[i],arr3[i]);
hm.put(arr1[i],rulemap);
}
}
for(String str: hm.keySet()){
System.out.println(str);
for(String s: hm.get(str).keySet()){
System.out.print(s+" "+hm.get(str).get(s)+" ");
}
System.out.println();
System.out.println();
}
}
public static void createtrie(HashMap<String,HashMap<String,String>> hm,f1trieNode head){
for(String str : hm.keySet()){
f1trieNode lastnode = insertF1(str,head);
f2trieNode head2 = new f2trieNode();
lastnode.ptr = head2;
for(String s: hm.get(str).keySet()){
insertF2(s,hm.get(str).get(s),head2);
}
}
}
public static f1trieNode insertF1(String s, f1trieNode head){
f1trieNode curr = head;
for(int i=0;i<s.length()-1;i++){
if(s.charAt(i)=='0'){
if(curr.zero == null)
curr.zero=new f1trieNode();
curr = curr.zero;
}
else{
if(curr.one == null)
curr.one = new f1trieNode();
curr = curr.one;
}
}
curr.isthere=true;
return curr;
}
public static void insertF2(String s, String rule, f2trieNode head){
f2trieNode curr = head;
for(int i=0;i<s.length()-1;i++){
if(s.charAt(i)=='0'){
if(curr.zero == null)
curr.zero=new f2trieNode();
curr = curr.zero;
}
else{
if(curr.one == null)
curr.one = new f2trieNode();
curr = curr.one;
}
}
curr.Rule = rule;
curr.isthere =true;
}
public static void converttosetpruning(f1trieNode head){
}
}