|
2 | 2 |
|
3 | 3 | import java.io.*;
|
4 | 4 | import java.lang.reflect.Field;
|
| 5 | +import java.util.Random; |
5 | 6 |
|
6 | 7 | import com.fasterxml.jackson.core.*;
|
7 | 8 |
|
@@ -120,6 +121,49 @@ public void testIssue207() throws Exception
|
120 | 121 | p.close();
|
121 | 122 | }
|
122 | 123 |
|
| 124 | + // [core#548] |
| 125 | + public void testQuadsIssue548() |
| 126 | + { |
| 127 | + Random r = new Random(42); |
| 128 | + ByteQuadsCanonicalizer root = ByteQuadsCanonicalizer.createRoot(); |
| 129 | + ByteQuadsCanonicalizer canon = root.makeChild(JsonFactory.Feature.collectDefaults()); |
| 130 | + |
| 131 | + int n_collisions = 25; |
| 132 | + int[] collisions = new int[n_collisions]; |
| 133 | + |
| 134 | + // generate collisions |
| 135 | + { |
| 136 | + int maybe = r.nextInt(); |
| 137 | + int hash = canon.calcHash(maybe); |
| 138 | + int target = ((hash & (2048-1)) << 2); |
| 139 | + |
| 140 | + for (int i = 0; i < collisions.length; ) { |
| 141 | + maybe = r.nextInt(); |
| 142 | + hash = canon.calcHash(maybe); |
| 143 | + int offset = ((hash & (2048-1)) << 2); |
| 144 | + |
| 145 | + if (offset == target) { |
| 146 | + collisions[i++] = maybe; |
| 147 | + } |
| 148 | + } |
| 149 | + } |
| 150 | + |
| 151 | + // fill spillover area until _needRehash is true. |
| 152 | + for(int i = 0; i < 22 ; i++) { |
| 153 | + canon.addName(Integer.toString(i), collisions[i]); |
| 154 | + } |
| 155 | + // canon._needRehash is now true, since the spillover is full |
| 156 | + |
| 157 | + // release table to update tableinfo with canon's data |
| 158 | + canon.release(); |
| 159 | + |
| 160 | + // new table pulls data from new tableinfo, that has a full spillover, but set _needRehash to false |
| 161 | + canon = root.makeChild(JsonFactory.Feature.collectDefaults()); |
| 162 | + |
| 163 | + // canon._needRehash == false, so this will try to add another item to the spillover area, even though it is full |
| 164 | + canon.addName(Integer.toString(22), collisions[22]); |
| 165 | + } |
| 166 | + |
123 | 167 | /*
|
124 | 168 | /**********************************************************
|
125 | 169 | /* Helper methods
|
|
0 commit comments