| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
package triegen_test |
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
func (t *randTrie) lookup(s []byte) (v uint8, sz int) { |
| 10 |
c0 := s[0] |
| 11 |
switch { |
| 12 |
case c0 < 0x80: |
| 13 |
return randValues[c0], 1 |
| 14 |
case c0 < 0xC2: |
| 15 |
return 0, 1 |
| 16 |
case c0 < 0xE0: |
| 17 |
if len(s) < 2 { |
| 18 |
return 0, 0 |
| 19 |
} |
| 20 |
i := randIndex[c0] |
| 21 |
c1 := s[1] |
| 22 |
if c1 < 0x80 || 0xC0 <= c1 { |
| 23 |
return 0, 1 |
| 24 |
} |
| 25 |
return t.lookupValue(uint32(i), c1), 2 |
| 26 |
case c0 < 0xF0: |
| 27 |
if len(s) < 3 { |
| 28 |
return 0, 0 |
| 29 |
} |
| 30 |
i := randIndex[c0] |
| 31 |
c1 := s[1] |
| 32 |
if c1 < 0x80 || 0xC0 <= c1 { |
| 33 |
return 0, 1 |
| 34 |
} |
| 35 |
o := uint32(i)<<6 + uint32(c1) |
| 36 |
i = randIndex[o] |
| 37 |
c2 := s[2] |
| 38 |
if c2 < 0x80 || 0xC0 <= c2 { |
| 39 |
return 0, 2 |
| 40 |
} |
| 41 |
return t.lookupValue(uint32(i), c2), 3 |
| 42 |
case c0 < 0xF8: |
| 43 |
if len(s) < 4 { |
| 44 |
return 0, 0 |
| 45 |
} |
| 46 |
i := randIndex[c0] |
| 47 |
c1 := s[1] |
| 48 |
if c1 < 0x80 || 0xC0 <= c1 { |
| 49 |
return 0, 1 |
| 50 |
} |
| 51 |
o := uint32(i)<<6 + uint32(c1) |
| 52 |
i = randIndex[o] |
| 53 |
c2 := s[2] |
| 54 |
if c2 < 0x80 || 0xC0 <= c2 { |
| 55 |
return 0, 2 |
| 56 |
} |
| 57 |
o = uint32(i)<<6 + uint32(c2) |
| 58 |
i = randIndex[o] |
| 59 |
c3 := s[3] |
| 60 |
if c3 < 0x80 || 0xC0 <= c3 { |
| 61 |
return 0, 3 |
| 62 |
} |
| 63 |
return t.lookupValue(uint32(i), c3), 4 |
| 64 |
} |
| 65 |
|
| 66 |
return 0, 1 |
| 67 |
} |
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
func (t *randTrie) lookupUnsafe(s []byte) uint8 { |
| 72 |
c0 := s[0] |
| 73 |
if c0 < 0x80 { |
| 74 |
return randValues[c0] |
| 75 |
} |
| 76 |
i := randIndex[c0] |
| 77 |
if c0 < 0xE0 { |
| 78 |
return t.lookupValue(uint32(i), s[1]) |
| 79 |
} |
| 80 |
i = randIndex[uint32(i)<<6+uint32(s[1])] |
| 81 |
if c0 < 0xF0 { |
| 82 |
return t.lookupValue(uint32(i), s[2]) |
| 83 |
} |
| 84 |
i = randIndex[uint32(i)<<6+uint32(s[2])] |
| 85 |
if c0 < 0xF8 { |
| 86 |
return t.lookupValue(uint32(i), s[3]) |
| 87 |
} |
| 88 |
return 0 |
| 89 |
} |
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
func (t *randTrie) lookupString(s string) (v uint8, sz int) { |
| 95 |
c0 := s[0] |
| 96 |
switch { |
| 97 |
case c0 < 0x80: |
| 98 |
return randValues[c0], 1 |
| 99 |
case c0 < 0xC2: |
| 100 |
return 0, 1 |
| 101 |
case c0 < 0xE0: |
| 102 |
if len(s) < 2 { |
| 103 |
return 0, 0 |
| 104 |
} |
| 105 |
i := randIndex[c0] |
| 106 |
c1 := s[1] |
| 107 |
if c1 < 0x80 || 0xC0 <= c1 { |
| 108 |
return 0, 1 |
| 109 |
} |
| 110 |
return t.lookupValue(uint32(i), c1), 2 |
| 111 |
case c0 < 0xF0: |
| 112 |
if len(s) < 3 { |
| 113 |
return 0, 0 |
| 114 |
} |
| 115 |
i := randIndex[c0] |
| 116 |
c1 := s[1] |
| 117 |
if c1 < 0x80 || 0xC0 <= c1 { |
| 118 |
return 0, 1 |
| 119 |
} |
| 120 |
o := uint32(i)<<6 + uint32(c1) |
| 121 |
i = randIndex[o] |
| 122 |
c2 := s[2] |
| 123 |
if c2 < 0x80 || 0xC0 <= c2 { |
| 124 |
return 0, 2 |
| 125 |
} |
| 126 |
return t.lookupValue(uint32(i), c2), 3 |
| 127 |
case c0 < 0xF8: |
| 128 |
if len(s) < 4 { |
| 129 |
return 0, 0 |
| 130 |
} |
| 131 |
i := randIndex[c0] |
| 132 |
c1 := s[1] |
| 133 |
if c1 < 0x80 || 0xC0 <= c1 { |
| 134 |
return 0, 1 |
| 135 |
} |
| 136 |
o := uint32(i)<<6 + uint32(c1) |
| 137 |
i = randIndex[o] |
| 138 |
c2 := s[2] |
| 139 |
if c2 < 0x80 || 0xC0 <= c2 { |
| 140 |
return 0, 2 |
| 141 |
} |
| 142 |
o = uint32(i)<<6 + uint32(c2) |
| 143 |
i = randIndex[o] |
| 144 |
c3 := s[3] |
| 145 |
if c3 < 0x80 || 0xC0 <= c3 { |
| 146 |
return 0, 3 |
| 147 |
} |
| 148 |
return t.lookupValue(uint32(i), c3), 4 |
| 149 |
} |
| 150 |
|
| 151 |
return 0, 1 |
| 152 |
} |
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
func (t *randTrie) lookupStringUnsafe(s string) uint8 { |
| 157 |
c0 := s[0] |
| 158 |
if c0 < 0x80 { |
| 159 |
return randValues[c0] |
| 160 |
} |
| 161 |
i := randIndex[c0] |
| 162 |
if c0 < 0xE0 { |
| 163 |
return t.lookupValue(uint32(i), s[1]) |
| 164 |
} |
| 165 |
i = randIndex[uint32(i)<<6+uint32(s[1])] |
| 166 |
if c0 < 0xF0 { |
| 167 |
return t.lookupValue(uint32(i), s[2]) |
| 168 |
} |
| 169 |
i = randIndex[uint32(i)<<6+uint32(s[2])] |
| 170 |
if c0 < 0xF8 { |
| 171 |
return t.lookupValue(uint32(i), s[3]) |
| 172 |
} |
| 173 |
return 0 |
| 174 |
} |
| 175 |
|
| 176 |
|
| 177 |
type randTrie struct{} |
| 178 |
|
| 179 |
func newRandTrie(i int) *randTrie { |
| 180 |
return &randTrie{} |
| 181 |
} |
| 182 |
|
| 183 |
|
| 184 |
func (t *randTrie) lookupValue(n uint32, b byte) uint8 { |
| 185 |
switch { |
| 186 |
default: |
| 187 |
return uint8(randValues[n<<6+uint32(b)]) |
| 188 |
} |
| 189 |
} |
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
var randValues = [3584]uint8{ |
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
0xc9: 0x0001, |
| 199 |
|
| 200 |
0x100: 0x0001, |
| 201 |
|
| 202 |
0x155: 0x0001, |
| 203 |
|
| 204 |
0x196: 0x0001, |
| 205 |
|
| 206 |
0x1ef: 0x0001, |
| 207 |
|
| 208 |
0x206: 0x0001, |
| 209 |
|
| 210 |
0x258: 0x0001, |
| 211 |
|
| 212 |
0x288: 0x0001, |
| 213 |
|
| 214 |
0x2f2: 0x0001, |
| 215 |
|
| 216 |
0x304: 0x0001, |
| 217 |
|
| 218 |
0x34b: 0x0001, |
| 219 |
|
| 220 |
0x3ba: 0x0001, |
| 221 |
|
| 222 |
0x3f5: 0x0001, |
| 223 |
|
| 224 |
0x41d: 0x0001, |
| 225 |
|
| 226 |
0x442: 0x0001, |
| 227 |
|
| 228 |
0x4bb: 0x0001, |
| 229 |
|
| 230 |
0x4e9: 0x0001, |
| 231 |
|
| 232 |
0x53e: 0x0001, |
| 233 |
|
| 234 |
0x55f: 0x0001, |
| 235 |
|
| 236 |
0x5b7: 0x0001, |
| 237 |
|
| 238 |
0x5d9: 0x0001, |
| 239 |
|
| 240 |
0x60e: 0x0001, |
| 241 |
|
| 242 |
0x652: 0x0001, |
| 243 |
|
| 244 |
0x68f: 0x0001, |
| 245 |
|
| 246 |
0x6dc: 0x0001, |
| 247 |
|
| 248 |
0x703: 0x0001, |
| 249 |
|
| 250 |
0x741: 0x0001, |
| 251 |
|
| 252 |
0x79b: 0x0001, |
| 253 |
|
| 254 |
0x7f1: 0x0001, |
| 255 |
|
| 256 |
0x833: 0x0001, |
| 257 |
|
| 258 |
0x853: 0x0001, |
| 259 |
|
| 260 |
0x8a2: 0x0001, |
| 261 |
|
| 262 |
0x8f8: 0x0001, |
| 263 |
|
| 264 |
0x917: 0x0001, |
| 265 |
|
| 266 |
0x945: 0x0001, |
| 267 |
|
| 268 |
0x99e: 0x0001, |
| 269 |
|
| 270 |
0x9fd: 0x0001, |
| 271 |
|
| 272 |
0xa0d: 0x0001, |
| 273 |
|
| 274 |
0xa66: 0x0001, |
| 275 |
|
| 276 |
0xaab: 0x0001, |
| 277 |
|
| 278 |
0xaea: 0x0001, |
| 279 |
|
| 280 |
0xb2d: 0x0001, |
| 281 |
|
| 282 |
0xb54: 0x0001, |
| 283 |
|
| 284 |
0xb90: 0x0001, |
| 285 |
|
| 286 |
0xbe5: 0x0001, |
| 287 |
|
| 288 |
0xc28: 0x0001, |
| 289 |
|
| 290 |
0xc7c: 0x0001, |
| 291 |
|
| 292 |
0xcbf: 0x0001, |
| 293 |
|
| 294 |
0xcc7: 0x0001, |
| 295 |
|
| 296 |
0xd34: 0x0001, |
| 297 |
|
| 298 |
0xd61: 0x0001, |
| 299 |
|
| 300 |
0xdb9: 0x0001, |
| 301 |
|
| 302 |
0xdda: 0x0001, |
| 303 |
} |
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
var randIndex = [5696]uint8{ |
| 308 |
|
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
0xe1: 0x02, 0xe3: 0x03, 0xe4: 0x04, |
| 313 |
0xea: 0x05, 0xeb: 0x06, 0xec: 0x07, |
| 314 |
0xf0: 0x10, 0xf1: 0x24, 0xf2: 0x3d, 0xf3: 0x4f, 0xf4: 0x56, |
| 315 |
|
| 316 |
0x107: 0x01, |
| 317 |
|
| 318 |
0x16c: 0x02, |
| 319 |
|
| 320 |
0x19c: 0x03, |
| 321 |
0x1ae: 0x04, |
| 322 |
|
| 323 |
0x1d8: 0x05, |
| 324 |
0x1f7: 0x06, |
| 325 |
|
| 326 |
0x20c: 0x07, |
| 327 |
|
| 328 |
0x24a: 0x08, |
| 329 |
|
| 330 |
0x2b6: 0x09, |
| 331 |
|
| 332 |
0x2d5: 0x0a, |
| 333 |
|
| 334 |
0x31a: 0x0b, |
| 335 |
|
| 336 |
0x373: 0x0c, |
| 337 |
|
| 338 |
0x38b: 0x0d, |
| 339 |
|
| 340 |
0x3f0: 0x0e, |
| 341 |
|
| 342 |
0x433: 0x0f, |
| 343 |
|
| 344 |
0x45d: 0x10, |
| 345 |
|
| 346 |
0x491: 0x08, 0x494: 0x09, 0x497: 0x0a, |
| 347 |
0x49b: 0x0b, 0x49c: 0x0c, |
| 348 |
0x4a1: 0x0d, |
| 349 |
0x4ad: 0x0e, |
| 350 |
0x4ba: 0x0f, |
| 351 |
|
| 352 |
0x4c1: 0x11, |
| 353 |
|
| 354 |
0x531: 0x12, |
| 355 |
|
| 356 |
0x546: 0x13, |
| 357 |
|
| 358 |
0x5ab: 0x14, |
| 359 |
|
| 360 |
0x5d4: 0x11, |
| 361 |
0x5fe: 0x11, |
| 362 |
|
| 363 |
0x618: 0x0a, |
| 364 |
|
| 365 |
0x65b: 0x15, |
| 366 |
|
| 367 |
0x6a0: 0x16, |
| 368 |
|
| 369 |
0x6d2: 0x17, |
| 370 |
0x6f6: 0x18, |
| 371 |
|
| 372 |
0x711: 0x19, |
| 373 |
|
| 374 |
0x768: 0x1a, |
| 375 |
|
| 376 |
0x783: 0x1b, |
| 377 |
|
| 378 |
0x7f9: 0x1c, |
| 379 |
|
| 380 |
0x831: 0x1d, |
| 381 |
|
| 382 |
0x85e: 0x1e, |
| 383 |
|
| 384 |
0x898: 0x1f, |
| 385 |
|
| 386 |
0x8c7: 0x18, |
| 387 |
0x8d5: 0x14, |
| 388 |
0x8f7: 0x20, |
| 389 |
0x8fe: 0x1f, |
| 390 |
|
| 391 |
0x905: 0x21, |
| 392 |
|
| 393 |
0x966: 0x03, |
| 394 |
|
| 395 |
0x981: 0x07, 0x983: 0x11, |
| 396 |
0x989: 0x12, 0x98a: 0x13, 0x98e: 0x14, 0x98f: 0x15, |
| 397 |
0x992: 0x16, 0x995: 0x17, 0x996: 0x18, |
| 398 |
0x998: 0x19, 0x999: 0x1a, 0x99b: 0x1b, 0x99f: 0x1c, |
| 399 |
0x9a3: 0x1d, |
| 400 |
0x9ad: 0x1e, 0x9af: 0x1f, |
| 401 |
0x9b0: 0x20, 0x9b1: 0x21, |
| 402 |
0x9b8: 0x22, 0x9bd: 0x23, |
| 403 |
|
| 404 |
0x9cd: 0x22, |
| 405 |
|
| 406 |
0xa0c: 0x08, |
| 407 |
|
| 408 |
0xa6f: 0x1c, |
| 409 |
|
| 410 |
0xa90: 0x1a, |
| 411 |
0xaaf: 0x23, |
| 412 |
|
| 413 |
0xae3: 0x19, |
| 414 |
0xae8: 0x24, |
| 415 |
0xafc: 0x25, |
| 416 |
|
| 417 |
0xb13: 0x26, |
| 418 |
|
| 419 |
0xb67: 0x1c, |
| 420 |
|
| 421 |
0xb8f: 0x0b, |
| 422 |
|
| 423 |
0xbcb: 0x27, |
| 424 |
0xbe7: 0x26, |
| 425 |
|
| 426 |
0xc34: 0x16, |
| 427 |
|
| 428 |
0xc62: 0x03, |
| 429 |
|
| 430 |
0xcbb: 0x12, |
| 431 |
|
| 432 |
0xcdf: 0x09, |
| 433 |
|
| 434 |
0xd34: 0x0a, |
| 435 |
|
| 436 |
0xd41: 0x1e, |
| 437 |
|
| 438 |
0xd83: 0x28, |
| 439 |
|
| 440 |
0xdc0: 0x15, |
| 441 |
|
| 442 |
0xe1a: 0x15, |
| 443 |
|
| 444 |
0xe65: 0x29, |
| 445 |
|
| 446 |
0xe86: 0x1f, |
| 447 |
|
| 448 |
0xeec: 0x18, |
| 449 |
|
| 450 |
0xf28: 0x2a, |
| 451 |
|
| 452 |
0xf53: 0x08, |
| 453 |
|
| 454 |
0xfa2: 0x2b, |
| 455 |
0xfaa: 0x17, |
| 456 |
|
| 457 |
0xfc0: 0x25, 0xfc2: 0x26, |
| 458 |
0xfc9: 0x27, 0xfcd: 0x28, 0xfce: 0x29, |
| 459 |
0xfd5: 0x2a, |
| 460 |
0xfd8: 0x2b, 0xfd9: 0x2c, 0xfdf: 0x2d, |
| 461 |
0xfe1: 0x2e, 0xfe2: 0x2f, 0xfe3: 0x30, 0xfe6: 0x31, |
| 462 |
0xfe9: 0x32, 0xfec: 0x33, 0xfed: 0x34, 0xfef: 0x35, |
| 463 |
0xff1: 0x36, 0xff2: 0x37, 0xff3: 0x38, 0xff4: 0x39, |
| 464 |
0xffa: 0x3a, 0xffc: 0x3b, 0xffe: 0x3c, |
| 465 |
|
| 466 |
0x102c: 0x2c, |
| 467 |
|
| 468 |
0x1074: 0x2c, |
| 469 |
|
| 470 |
0x108c: 0x08, |
| 471 |
0x10a0: 0x2d, |
| 472 |
|
| 473 |
0x10e8: 0x10, |
| 474 |
|
| 475 |
0x110f: 0x13, |
| 476 |
|
| 477 |
0x114b: 0x2e, |
| 478 |
|
| 479 |
0x118b: 0x23, |
| 480 |
0x119d: 0x0c, |
| 481 |
|
| 482 |
0x11c3: 0x12, |
| 483 |
0x11f9: 0x0f, |
| 484 |
|
| 485 |
0x121e: 0x1b, |
| 486 |
|
| 487 |
0x1270: 0x2f, |
| 488 |
|
| 489 |
0x128a: 0x1b, |
| 490 |
0x12a7: 0x02, |
| 491 |
|
| 492 |
0x12fb: 0x14, |
| 493 |
|
| 494 |
0x1333: 0x30, |
| 495 |
|
| 496 |
0x134d: 0x31, |
| 497 |
|
| 498 |
0x138e: 0x15, |
| 499 |
|
| 500 |
0x13f4: 0x32, |
| 501 |
|
| 502 |
0x141b: 0x33, |
| 503 |
|
| 504 |
0x1448: 0x3e, 0x1449: 0x3f, 0x144a: 0x40, 0x144f: 0x41, |
| 505 |
0x1459: 0x42, 0x145c: 0x43, 0x145e: 0x44, 0x145f: 0x45, |
| 506 |
0x1468: 0x46, 0x1469: 0x47, 0x146c: 0x48, 0x146d: 0x49, 0x146e: 0x4a, |
| 507 |
0x1472: 0x4b, 0x1473: 0x4c, |
| 508 |
0x1479: 0x4d, 0x147b: 0x4e, |
| 509 |
|
| 510 |
0x1480: 0x34, |
| 511 |
0x1499: 0x11, |
| 512 |
0x14b6: 0x2c, |
| 513 |
|
| 514 |
0x14e4: 0x0d, |
| 515 |
|
| 516 |
0x1527: 0x08, |
| 517 |
|
| 518 |
0x1555: 0x2b, |
| 519 |
|
| 520 |
0x15b2: 0x35, |
| 521 |
|
| 522 |
0x15f2: 0x1c, 0x15f4: 0x29, |
| 523 |
|
| 524 |
0x1600: 0x50, 0x1603: 0x51, |
| 525 |
0x1608: 0x52, 0x160a: 0x53, 0x160d: 0x54, 0x160e: 0x55, |
| 526 |
} |
| 527 |
|
| 528 |
|
| 529 |
|
| 530 |
|
| 531 |
func (t *multiTrie) lookup(s []byte) (v uint64, sz int) { |
| 532 |
c0 := s[0] |
| 533 |
switch { |
| 534 |
case c0 < 0x80: |
| 535 |
return t.ascii[c0], 1 |
| 536 |
case c0 < 0xC2: |
| 537 |
return 0, 1 |
| 538 |
case c0 < 0xE0: |
| 539 |
if len(s) < 2 { |
| 540 |
return 0, 0 |
| 541 |
} |
| 542 |
i := t.utf8Start[c0] |
| 543 |
c1 := s[1] |
| 544 |
if c1 < 0x80 || 0xC0 <= c1 { |
| 545 |
return 0, 1 |
| 546 |
} |
| 547 |
return t.lookupValue(uint32(i), c1), 2 |
| 548 |
case c0 < 0xF0: |
| 549 |
if len(s) < 3 { |
| 550 |
return 0, 0 |
| 551 |
} |
| 552 |
i := t.utf8Start[c0] |
| 553 |
c1 := s[1] |
| 554 |
if c1 < 0x80 || 0xC0 <= c1 { |
| 555 |
return 0, 1 |
| 556 |
} |
| 557 |
o := uint32(i)<<6 + uint32(c1) |
| 558 |
i = multiIndex[o] |
| 559 |
c2 := s[2] |
| 560 |
if c2 < 0x80 || 0xC0 <= c2 { |
| 561 |
return 0, 2 |
| 562 |
} |
| 563 |
return t.lookupValue(uint32(i), c2), 3 |
| 564 |
case c0 < 0xF8: |
| 565 |
if len(s) < 4 { |
| 566 |
return 0, 0 |
| 567 |
} |
| 568 |
i := t.utf8Start[c0] |
| 569 |
c1 := s[1] |
| 570 |
if c1 < 0x80 || 0xC0 <= c1 { |
| 571 |
return 0, 1 |
| 572 |
} |
| 573 |
o := uint32(i)<<6 + uint32(c1) |
| 574 |
i = multiIndex[o] |
| 575 |
c2 := s[2] |
| 576 |
if c2 < 0x80 || 0xC0 <= c2 { |
| 577 |
return 0, 2 |
| 578 |
} |
| 579 |
o = uint32(i)<<6 + uint32(c2) |
| 580 |
i = multiIndex[o] |
| 581 |
c3 := s[3] |
| 582 |
if c3 < 0x80 || 0xC0 <= c3 { |
| 583 |
return 0, 3 |
| 584 |
} |
| 585 |
return t.lookupValue(uint32(i), c3), 4 |
| 586 |
} |
| 587 |
|
| 588 |
return 0, 1 |
| 589 |
} |
| 590 |
|
| 591 |
|
| 592 |
|
| 593 |
func (t *multiTrie) lookupUnsafe(s []byte) uint64 { |
| 594 |
c0 := s[0] |
| 595 |
if c0 < 0x80 { |
| 596 |
return t.ascii[c0] |
| 597 |
} |
| 598 |
i := t.utf8Start[c0] |
| 599 |
if c0 < 0xE0 { |
| 600 |
return t.lookupValue(uint32(i), s[1]) |
| 601 |
} |
| 602 |
i = multiIndex[uint32(i)<<6+uint32(s[1])] |
| 603 |
if c0 < 0xF0 { |
| 604 |
return t.lookupValue(uint32(i), s[2]) |
| 605 |
} |
| 606 |
i = multiIndex[uint32(i)<<6+uint32(s[2])] |
| 607 |
if c0 < 0xF8 { |
| 608 |
return t.lookupValue(uint32(i), s[3]) |
| 609 |
} |
| 610 |
return 0 |
| 611 |
} |
| 612 |
|
| 613 |
|
| 614 |
|
| 615 |
|
| 616 |
func (t *multiTrie) lookupString(s string) (v uint64, sz int) { |
| 617 |
c0 := s[0] |
| 618 |
switch { |
| 619 |
case c0 < 0x80: |
| 620 |
return t.ascii[c0], 1 |
| 621 |
case c0 < 0xC2: |
| 622 |
return 0, 1 |
| 623 |
case c0 < 0xE0: |
| 624 |
if len(s) < 2 { |
| 625 |
return 0, 0 |
| 626 |
} |
| 627 |
i := t.utf8Start[c0] |
| 628 |
c1 := s[1] |
| 629 |
if c1 < 0x80 || 0xC0 <= c1 { |
| 630 |
return 0, 1 |
| 631 |
} |
| 632 |
return t.lookupValue(uint32(i), c1), 2 |
| 633 |
case c0 < 0xF0: |
| 634 |
if len(s) < 3 { |
| 635 |
return 0, 0 |
| 636 |
} |
| 637 |
i := t.utf8Start[c0] |
| 638 |
c1 := s[1] |
| 639 |
if c1 < 0x80 || 0xC0 <= c1 { |
| 640 |
return 0, 1 |
| 641 |
} |
| 642 |
o := uint32(i)<<6 + uint32(c1) |
| 643 |
i = multiIndex[o] |
| 644 |
c2 := s[2] |
| 645 |
if c2 < 0x80 || 0xC0 <= c2 { |
| 646 |
return 0, 2 |
| 647 |
} |
| 648 |
return t.lookupValue(uint32(i), c2), 3 |
| 649 |
case c0 < 0xF8: |
| 650 |
if len(s) < 4 { |
| 651 |
return 0, 0 |
| 652 |
} |
| 653 |
i := t.utf8Start[c0] |
| 654 |
c1 := s[1] |
| 655 |
if c1 < 0x80 || 0xC0 <= c1 { |
| 656 |
return 0, 1 |
| 657 |
} |
| 658 |
o := uint32(i)<<6 + uint32(c1) |
| 659 |
i = multiIndex[o] |
| 660 |
c2 := s[2] |
| 661 |
if c2 < 0x80 || 0xC0 <= c2 { |
| 662 |
return 0, 2 |
| 663 |
} |
| 664 |
o = uint32(i)<<6 + uint32(c2) |
| 665 |
i = multiIndex[o] |
| 666 |
c3 := s[3] |
| 667 |
if c3 < 0x80 || 0xC0 <= c3 { |
| 668 |
return 0, 3 |
| 669 |
} |
| 670 |
return t.lookupValue(uint32(i), c3), 4 |
| 671 |
} |
| 672 |
|
| 673 |
return 0, 1 |
| 674 |
} |
| 675 |
|
| 676 |
|
| 677 |
|
| 678 |
func (t *multiTrie) lookupStringUnsafe(s string) uint64 { |
| 679 |
c0 := s[0] |
| 680 |
if c0 < 0x80 { |
| 681 |
return t.ascii[c0] |
| 682 |
} |
| 683 |
i := t.utf8Start[c0] |
| 684 |
if c0 < 0xE0 { |
| 685 |
return t.lookupValue(uint32(i), s[1]) |
| 686 |
} |
| 687 |
i = multiIndex[uint32(i)<<6+uint32(s[1])] |
| 688 |
if c0 < 0xF0 { |
| 689 |
return t.lookupValue(uint32(i), s[2]) |
| 690 |
} |
| 691 |
i = multiIndex[uint32(i)<<6+uint32(s[2])] |
| 692 |
if c0 < 0xF8 { |
| 693 |
return t.lookupValue(uint32(i), s[3]) |
| 694 |
} |
| 695 |
return 0 |
| 696 |
} |
| 697 |
|
| 698 |
|
| 699 |
type multiTrie struct { |
| 700 |
ascii []uint64 |
| 701 |
utf8Start []uint8 |
| 702 |
} |
| 703 |
|
| 704 |
func newMultiTrie(i int) *multiTrie { |
| 705 |
h := multiTrieHandles[i] |
| 706 |
return &multiTrie{multiValues[uint32(h.ascii)<<6:], multiIndex[uint32(h.multi)<<6:]} |
| 707 |
} |
| 708 |
|
| 709 |
type multiTrieHandle struct { |
| 710 |
ascii, multi uint8 |
| 711 |
} |
| 712 |
|
| 713 |
|
| 714 |
var multiTrieHandles = [5]multiTrieHandle{ |
| 715 |
{0, 0}, |
| 716 |
{0, 23}, |
| 717 |
{0, 23}, |
| 718 |
{0, 24}, |
| 719 |
{30, 25}, |
| 720 |
} |
| 721 |
|
| 722 |
|
| 723 |
func (t *multiTrie) lookupValue(n uint32, b byte) uint64 { |
| 724 |
switch { |
| 725 |
default: |
| 726 |
return uint64(multiValues[n<<6+uint32(b)]) |
| 727 |
} |
| 728 |
} |
| 729 |
|
| 730 |
|
| 731 |
|
| 732 |
var multiValues = [2048]uint64{ |
| 733 |
|
| 734 |
0x03: 0x6e361699800b9fb8, 0x04: 0x52d3935a34f6f0b, 0x05: 0x2948319393e7ef10, |
| 735 |
0x07: 0x20f03b006704f663, 0x08: 0x6c15c0732bb2495f, 0x09: 0xe54e2c59d953551, |
| 736 |
0x0f: 0x33d8a825807d8037, 0x10: 0x6ecd93cb12168b92, 0x11: 0x6a81c9c0ce86e884, |
| 737 |
0x1f: 0xa03e77aac8be79b, 0x20: 0x28591d0e7e486efa, 0x21: 0x716fa3bc398dec8, |
| 738 |
0x3f: 0x4fd3bcfa72bce8b0, |
| 739 |
|
| 740 |
0x40: 0x3cbaef3db8ba5f12, 0x41: 0x2d262347c1f56357, |
| 741 |
0x7f: 0x782caa2d25a418a9, |
| 742 |
|
| 743 |
|
| 744 |
0xc0: 0x6bbd1f937b1ff5d2, 0xc1: 0x732e23088d2eb8a4, |
| 745 |
|
| 746 |
0x13f: 0x56f8c4c82f5962dc, |
| 747 |
|
| 748 |
0x140: 0x57dc4544729a5da2, 0x141: 0x2f62f9cd307ffa0d, |
| 749 |
|
| 750 |
0x1bf: 0x7bf4d0ebf302a088, |
| 751 |
|
| 752 |
0x1c0: 0x1f0d67f249e59931, 0x1c1: 0x3011def73aa550c7, |
| 753 |
|
| 754 |
0x23f: 0x5de81c1dff6bf29d, |
| 755 |
|
| 756 |
0x240: 0x752c035737b825e8, 0x241: 0x1e793399081e3bb3, |
| 757 |
|
| 758 |
0x2bf: 0x6a28f01979cbf059, |
| 759 |
|
| 760 |
0x2c0: 0x373a4b0f2cbd4c74, 0x2c1: 0x4fd2c288683b767c, |
| 761 |
|
| 762 |
0x33f: 0x5a10ffa9e29184fb, |
| 763 |
|
| 764 |
0x340: 0x700f9bdb53fff6a5, 0x341: 0xcde93df0427eb79, |
| 765 |
|
| 766 |
0x3bf: 0x74071288fff39c76, |
| 767 |
|
| 768 |
0x3c0: 0x481fc2f510e5268a, 0x3c1: 0x7565c28164204849, |
| 769 |
|
| 770 |
0x43f: 0x5676a62fd49c6bec, |
| 771 |
|
| 772 |
0x440: 0x2f2d15776cbafc6b, 0x441: 0x4c55e8dc0ff11a3f, |
| 773 |
|
| 774 |
0x4bf: 0x69d6f0fe711fafc9, |
| 775 |
|
| 776 |
0x4c0: 0x33181de28cfb062d, 0x4c1: 0x2ef3adc6bb2f2d02, |
| 777 |
|
| 778 |
0x53f: 0xe03b31814c95f8b, |
| 779 |
|
| 780 |
0x540: 0x3bf6dc9a1c115603, 0x541: 0x6984ec9b7f51f7fc, |
| 781 |
|
| 782 |
0x5bf: 0x3c02ea92fb168559, |
| 783 |
|
| 784 |
0x5c0: 0x1badfe42e7629494, 0x5c1: 0x6dc4a554005f7645, |
| 785 |
|
| 786 |
0x63f: 0x3bb2ed2a72748f4b, |
| 787 |
|
| 788 |
0x640: 0x291354cd6767ec10, 0x641: 0x2c3a4715e3c070d6, |
| 789 |
|
| 790 |
0x6bf: 0x352711cfb7236418, |
| 791 |
|
| 792 |
0x6c0: 0x3a59d34fb8bceda, 0x6c1: 0x5e90d8ebedd64fa1, |
| 793 |
|
| 794 |
0x73f: 0x7191a77b28d23110, |
| 795 |
|
| 796 |
0x740: 0x4ca7f0c1623423d8, 0x741: 0x4f7156d996e2d0de, |
| 797 |
|
| 798 |
|
| 799 |
} |
| 800 |
|
| 801 |
|
| 802 |
|
| 803 |
var multiIndex = [1856]uint8{ |
| 804 |
|
| 805 |
|
| 806 |
|
| 807 |
|
| 808 |
0xc2: 0x01, 0xc3: 0x02, 0xc4: 0x03, 0xc7: 0x04, |
| 809 |
0xc8: 0x05, 0xcf: 0x06, |
| 810 |
0xd0: 0x07, |
| 811 |
0xdf: 0x08, |
| 812 |
0xe0: 0x02, 0xe1: 0x03, 0xe2: 0x04, 0xe3: 0x05, 0xe4: 0x06, 0xe7: 0x07, |
| 813 |
0xe8: 0x08, 0xef: 0x09, |
| 814 |
0xf0: 0x0e, 0xf1: 0x11, 0xf2: 0x13, 0xf3: 0x15, 0xf4: 0x17, |
| 815 |
|
| 816 |
0x120: 0x09, |
| 817 |
0x13f: 0x0a, |
| 818 |
|
| 819 |
0x140: 0x0b, |
| 820 |
0x17f: 0x0c, |
| 821 |
|
| 822 |
0x180: 0x0d, |
| 823 |
|
| 824 |
0x1ff: 0x0e, |
| 825 |
|
| 826 |
0x200: 0x0f, |
| 827 |
|
| 828 |
0x27f: 0x10, |
| 829 |
|
| 830 |
0x280: 0x11, |
| 831 |
|
| 832 |
0x2ff: 0x12, |
| 833 |
|
| 834 |
0x300: 0x13, |
| 835 |
|
| 836 |
0x37f: 0x14, |
| 837 |
|
| 838 |
0x380: 0x15, |
| 839 |
|
| 840 |
0x3ff: 0x16, |
| 841 |
|
| 842 |
0x410: 0x0a, |
| 843 |
0x41f: 0x0b, |
| 844 |
0x420: 0x0c, |
| 845 |
0x43f: 0x0d, |
| 846 |
|
| 847 |
0x440: 0x17, |
| 848 |
|
| 849 |
0x4bf: 0x18, |
| 850 |
|
| 851 |
0x4c0: 0x0f, |
| 852 |
0x4ff: 0x10, |
| 853 |
|
| 854 |
0x500: 0x19, |
| 855 |
|
| 856 |
0x540: 0x12, |
| 857 |
|
| 858 |
0x5bf: 0x1a, |
| 859 |
|
| 860 |
0x5ff: 0x14, |
| 861 |
|
| 862 |
0x600: 0x1b, |
| 863 |
|
| 864 |
0x640: 0x16, |
| 865 |
|
| 866 |
|
| 867 |
0x6c2: 0x01, 0x6c3: 0x02, 0x6c4: 0x03, 0x6c7: 0x04, |
| 868 |
0x6c8: 0x05, 0x6cf: 0x06, |
| 869 |
0x6d0: 0x07, |
| 870 |
0x6df: 0x08, |
| 871 |
0x6e0: 0x02, 0x6e1: 0x03, 0x6e2: 0x04, 0x6e3: 0x05, 0x6e4: 0x06, 0x6e7: 0x07, |
| 872 |
0x6e8: 0x08, 0x6ef: 0x09, |
| 873 |
|
| 874 |
0x730: 0x0e, 0x731: 0x11, 0x732: 0x13, 0x733: 0x15, 0x734: 0x17, |
| 875 |
} |