345
|
1 package alice.test.topology.fish;
|
|
2
|
|
3 import java.util.Collections;
|
|
4 import java.util.Comparator;
|
370
|
5 import java.util.function.Function;
|
|
6 import java.util.function.ToDoubleFunction;
|
|
7 import java.util.function.ToIntFunction;
|
|
8 import java.util.function.ToLongFunction;
|
345
|
9
|
|
10 import alice.codesegment.CodeSegment;
|
|
11 import alice.datasegment.CommandType;
|
|
12 import alice.datasegment.Receiver;
|
|
13
|
|
14 public class WidthReceiver extends CodeSegment {
|
|
15
|
|
16 public Receiver widths = ids.create(CommandType.TAKE);
|
|
17 public Receiver routing = ids.create(CommandType.PEEK);
|
|
18
|
|
19 @Override
|
|
20 public void run() {
|
|
21 int width = this.widths.asInteger();
|
|
22 String from = this.widths.from;
|
|
23 RoutingTable routing = this.routing.asClass(RoutingTable.class);
|
|
24 Routing newRouting = new Routing(from, width);
|
|
25 boolean update = false;
|
|
26 for (Routing r : routing.table) {
|
|
27 if (r.id == newRouting.id) {
|
|
28 routing.sumWidth -= r.width;
|
|
29 routing.sumWidth += newRouting.width;
|
|
30 r.width = width;
|
|
31 update = true;
|
|
32 break;
|
|
33 }
|
|
34 }
|
|
35 if (!update) {
|
|
36 routing.table.add(newRouting);
|
|
37 Collections.sort(routing.table, new Comparator<Routing>() {
|
|
38 @Override
|
|
39 public int compare(Routing o1, Routing o2) {
|
|
40 return o1.id - o2.id;
|
|
41 }
|
370
|
42
|
|
43 @Override
|
|
44 public Comparator<Routing> reversed() {
|
|
45 return null;
|
|
46 }
|
|
47
|
|
48 @Override
|
|
49 public Comparator<Routing> thenComparing(
|
|
50 Comparator<? super Routing> other) {
|
|
51 return null;
|
|
52 }
|
|
53
|
|
54 @Override
|
|
55 public <U> Comparator<Routing> thenComparing(
|
|
56 Function<? super Routing, ? extends U> keyExtractor,
|
|
57 Comparator<? super U> keyComparator) {
|
|
58 return null;
|
|
59 }
|
|
60
|
|
61 @Override
|
|
62 public <U extends Comparable<? super U>> Comparator<Routing> thenComparing(
|
|
63 Function<? super Routing, ? extends U> keyExtractor) {
|
|
64 return null;
|
|
65 }
|
|
66
|
|
67 @Override
|
|
68 public Comparator<Routing> thenComparingInt(
|
|
69 ToIntFunction<? super Routing> keyExtractor) {
|
|
70 return null;
|
|
71 }
|
|
72
|
|
73 @Override
|
|
74 public Comparator<Routing> thenComparingLong(
|
|
75 ToLongFunction<? super Routing> keyExtractor) {
|
|
76 return null;
|
|
77 }
|
|
78
|
|
79 @Override
|
|
80 public Comparator<Routing> thenComparingDouble(
|
|
81 ToDoubleFunction<? super Routing> keyExtractor) {
|
|
82 return null;
|
|
83 }
|
345
|
84 });
|
|
85 routing.sumWidth += width;
|
|
86 }
|
|
87
|
|
88 System.out.println("SUM WIDTH: " + routing.sumWidth);
|
|
89
|
|
90 System.out.println("NODE NUM: " + routing.table.size());
|
|
91
|
|
92 ods.update("width", routing.sumWidth);
|
|
93 ods.update("routing", routing);
|
|
94
|
|
95 WidthReceiver cs = new WidthReceiver();
|
|
96 cs.widths.setKey("widths", this.widths.index);
|
|
97 cs.routing.setKey("routing");
|
|
98 //cs.routing.setKey("routing", this.routing.index);
|
|
99 }
|
|
100
|
|
101 }
|