MCPcopy Create free account
hub / github.com/BaseXdb/basex / add

Method add

basex-core/src/main/java/org/basex/index/stats/Stats.java:106–151  ·  view source on GitHub ↗

Adds a value. All values are first treated as integer values. If a value cannot be converted to an integer, it is treated as double value. If conversion fails again, it is handled as string category. Next, all values are cached. As soon as their number exceeds a maximum, the cached values are skippe

(final byte[] value, final MetaData meta)

Source from the content-addressed store, hash-verified

104 * @param meta meta data
105 */
106 public void add(final byte[] value, final MetaData meta) {
107 byte t = type;
108 final int vl = value.length;
109 // only analyze non-empty values
110 if(vl > 0) {
111 // start with integer type
112 if(t == NONE) {
113 t = INTEGER;
114 }
115 // try to save new value as integer
116 if(t == INTEGER) {
117 final long d = toLong(value);
118 if(d == Long.MIN_VALUE) {
119 t = DOUBLE;
120 } else {
121 if(min > d) min = d;
122 if(max < d) max = d;
123 }
124 }
125 // try to save new value as double
126 if(t == DOUBLE) {
127 final double d = toDouble(value);
128 if(Double.isNaN(d)) {
129 t = STRING;
130 } else {
131 if(min > d) min = d;
132 if(max < d) max = d;
133 }
134 }
135 } else {
136 t = STRING;
137 }
138 type = t;
139
140 // save distinct values
141 if(values != null) {
142 if(vl > meta.maxlen || vl > 0 && ws(value)) {
143 // give up categories if string is too long or only consists of whitespace
144 values = null;
145 } else {
146 values.put(value, Math.max(1, values.get(value) + 1));
147 // give up categories if number of entries exceeds limit
148 if(values.size() > meta.maxcats) values = null;
149 }
150 }
151 }
152
153 /**
154 * Getter for leaf flag.

Callers 3

optimizeMethod · 0.95
indexMethod · 0.95
storeMethod · 0.95

Calls 8

isNaNMethod · 0.80
getMethod · 0.65
sizeMethod · 0.65
toLongMethod · 0.45
toDoubleMethod · 0.45
wsMethod · 0.45
putMethod · 0.45
maxMethod · 0.45

Tested by

no test coverage detected