diff options
author | 2021-08-16 01:20:05 +0200 | |
---|---|---|
committer | 2021-08-16 01:20:05 +0200 | |
commit | 8d648ea32d529f781158bad1c5a2b17a5f1e6e41 (patch) | |
tree | c62c60a1d59a6abf06337599f02bf0261ba66757 /model-data | |
parent | First version of query builder (diff) | |
download | refinery-8d648ea32d529f781158bad1c5a2b17a5f1e6e41.tar.gz refinery-8d648ea32d529f781158bad1c5a2b17a5f1e6e41.tar.zst refinery-8d648ea32d529f781158bad1c5a2b17a5f1e6e41.zip |
Caching tuple1 objects
Diffstat (limited to 'model-data')
-rw-r--r-- | model-data/src/main/java/org/eclipse/viatra/solver/data/model/Tuple.java | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/model-data/src/main/java/org/eclipse/viatra/solver/data/model/Tuple.java b/model-data/src/main/java/org/eclipse/viatra/solver/data/model/Tuple.java index 4e7e7ba7..ca6548a4 100644 --- a/model-data/src/main/java/org/eclipse/viatra/solver/data/model/Tuple.java +++ b/model-data/src/main/java/org/eclipse/viatra/solver/data/model/Tuple.java | |||
@@ -1,13 +1,17 @@ | |||
1 | package org.eclipse.viatra.solver.data.model; | 1 | package org.eclipse.viatra.solver.data.model; |
2 | 2 | ||
3 | import java.util.ArrayList; | ||
3 | import java.util.Arrays; | 4 | import java.util.Arrays; |
5 | import java.util.List; | ||
4 | 6 | ||
5 | public abstract class Tuple { | 7 | public abstract class Tuple { |
6 | private static final int CUSTOMTUPLESIZE = 2; | 8 | private static final int CUSTOMTUPLESIZE = 2; |
9 | protected static final List<Tuple1> tuple1Cash = new ArrayList<>(1024); | ||
7 | 10 | ||
8 | public abstract int getSize(); | 11 | public abstract int getSize(); |
9 | public abstract int get(int element); | 12 | public abstract int get(int element); |
10 | public abstract int[] toArray(); | 13 | public abstract int[] toArray(); |
14 | |||
11 | @Override | 15 | @Override |
12 | public String toString() { | 16 | public String toString() { |
13 | StringBuilder b = new StringBuilder(); | 17 | StringBuilder b = new StringBuilder(); |
@@ -21,8 +25,18 @@ public abstract class Tuple { | |||
21 | b.append("]"); | 25 | b.append("]"); |
22 | return b.toString(); | 26 | return b.toString(); |
23 | } | 27 | } |
28 | |||
24 | public static Tuple1 of1(int value) { | 29 | public static Tuple1 of1(int value) { |
25 | return new Tuple1(value); | 30 | if(value < tuple1Cash.size()) { |
31 | return tuple1Cash.get(value); | ||
32 | } else { | ||
33 | Tuple1 newlyCreated = null; | ||
34 | while(value >= tuple1Cash.size()) { | ||
35 | newlyCreated = new Tuple1(tuple1Cash.size()); | ||
36 | tuple1Cash.add(newlyCreated); | ||
37 | } | ||
38 | return newlyCreated; | ||
39 | } | ||
26 | } | 40 | } |
27 | 41 | ||
28 | public static Tuple of(int... values) { | 42 | public static Tuple of(int... values) { |