Z3
 
Loading...
Searching...
No Matches
Statistics.java
Go to the documentation of this file.
1
18package com.microsoft.z3;
19
20import java.lang.ref.ReferenceQueue;
21
25public class Statistics extends Z3Object {
30 public static class Entry
31 {
35 public String Key;
36
40 public int getUIntValue()
41 {
42 return m_int;
43 }
44
48 public double getDoubleValue()
49 {
50 return m_double;
51 }
52
56 public boolean isUInt()
57 {
58 return m_is_int;
59 }
60
64 public boolean isDouble()
65 {
66 return m_is_double;
67 }
68
74 public String getValueString()
75 {
76 if (isUInt()) {
77 return Integer.toString(m_int);
78 } else if (isDouble()) {
79 return Double.toString(m_double);
80 } else {
81 throw new Z3Exception("Unknown statistical entry type");
82 }
83 }
84
88 @Override
89 public String toString() {
90 return Key + ": " + getValueString();
91 }
92
93 private boolean m_is_int = false;
94 private boolean m_is_double = false;
95 private int m_int = 0;
96 private double m_double = 0.0;
97
98 Entry(String k, int v)
99 {
100 Key = k;
101 m_is_int = true;
102 m_int = v;
103 }
104
105 Entry(String k, double v)
106 {
107 Key = k;
108 m_is_double = true;
109 m_double = v;
110 }
111 }
112
116 @Override
117 public String toString()
118 {
119 return Native.statsToString(getContext().nCtx(), getNativeObject());
120 }
121
125 public int size()
126 {
127 return Native.statsSize(getContext().nCtx(), getNativeObject());
128 }
129
135 public Entry[] getEntries()
136 {
137
138 int n = size();
139 Entry[] res = new Entry[n];
140 for (int i = 0; i < n; i++)
141 {
142 Entry e;
143 String k = Native.statsGetKey(getContext().nCtx(), getNativeObject(), i);
144 if (Native.statsIsUint(getContext().nCtx(), getNativeObject(), i)) {
145 e = new Entry(k, Native.statsGetUintValue(getContext().nCtx(),
146 getNativeObject(), i));
147 } else if (Native.statsIsDouble(getContext().nCtx(), getNativeObject(), i)) {
148 e = new Entry(k, Native.statsGetDoubleValue(getContext().nCtx(),
149 getNativeObject(), i));
150 } else {
151 throw new Z3Exception("Unknown data entry value");
152 }
153 res[i] = e;
154 }
155 return res;
156 }
157
161 public String[] getKeys()
162 {
163 int n = size();
164 String[] res = new String[n];
165 for (int i = 0; i < n; i++)
166 res[i] = Native.statsGetKey(getContext().nCtx(), getNativeObject(), i);
167 return res;
168 }
169
177 public Entry get(String key)
178 {
179 int n = size();
180 Entry[] es = getEntries();
181 for (int i = 0; i < n; i++) {
182 if (es[i].Key.equals(key)) {
183 return es[i];
184 }
185 }
186 return null;
187 }
188
189 Statistics(Context ctx, long obj)
190 {
191 super(ctx, obj);
192 }
193
194 @Override
195 void incRef() {
196 Native.statsIncRef(getContext().nCtx(), getNativeObject());
197 }
198
199 @Override
200 void addToReferenceQueue() {
201 getContext().getReferenceQueue().storeReference(this, StatisticsRef::new);
202 }
203
204 private static class StatisticsRef extends Z3ReferenceQueue.Reference<Statistics> {
205
206 private StatisticsRef(Statistics referent, ReferenceQueue<Z3Object> q) {
207 super(referent, q);
208 }
209
210 @Override
211 void decRef(Context ctx, long z3Obj) {
212 Native.statsDecRef(ctx.nCtx(), z3Obj);
213 }
214 }
215}