|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 |
--[[ Counts table entries when #tableObject will not work. (...or would also fail on tables using non-numeric keys.)--]] endend--[[ Description This is the only thing that should be used in table.sort's "comp" function. It allows a data description of how to sort tables to be written, instead of writing a custom sort function over and over again, you just create a single table that defines the sort ordering for a general table type. Arguments: entry1 (table) An entry in the table being sorted entry2 (table) Another entry in the table being sorted sortKey (non nil) A key in the entry arguments (tableX[sortKey]) to be used for sorting. sortKeys (table) A table whose keys are all keys in entryX and whose values are all tables. sortKeys options: isNumeric - used if a string field should be converted to a number for comparison isId64 - used for id64 fields which need special comparison functions caseInsensitive - used for case insensitive string comparison tiebreaker - the next key to be used if this one is tied tieBreakerSortOrder - the sort order to be used with the tie breaker key reverseTiebreakerSortOrder - a boolean which if set to true causes the tie breaker to use the opposite of the current sort order sortOrder (number) Must be ZO_SORT_ORDER_UP or ZO_SORT_ORDER_DOWN Return: When sortOrder is ZO_SORT_ORDER_UP: entry1[sortKey] < entry2[sortKey] When sortOrder is ZO_SORT_ORDER_DOWN: entry1[sortKey] > entry2[sortKey]--]]local validOrderingTypes ={ ["number"] = true, ["string"] = true, ["boolean"] = true} if(boolean == true) then return 1 end return 0end--[[ Common constants and types to make sorting a little easier.--]]-- Sort from A - ZZO_SORT_ORDER_UP = true-- Sort from Z - AZO_SORT_ORDER_DOWN = false-- Sort by the name field of your entry. Assumes the table being sorted is full of entries which are-- also tables; those entries having a key named "name".ZO_SORT_BY_NAME = { ["name"] = {} }ZO_SORT_BY_NAME_NUMERIC = { ["name"] = { isNumeric = true } }local IS_LESS_THAN = -1local IS_EQUAL_TO = 0local IS_GREATER_THAN = 1 end end local value1Text value1Text = "nil" else end local value2Text value2Text = "nil" else end internalassert(false, string.format("%s is not a valid sort key for this data. value1 = %s. value2 = %s.", sortKey or "[nil key]", value1Text, value2Text)) return false end if value1Type == "boolean" then end local compareResult if sortKeys[sortKey].isId64 then else if sortKeys[sortKey].isNumeric then elseif value1Type == "string" then if sortKeys[sortKey].caseInsensitive then end end compareResult = IS_LESS_THAN compareResult = IS_GREATER_THAN else compareResult = IS_EQUAL_TO end end -- The two pieces of data are equal, now this needs to tiebreaker to a different key and recurse. -- This is so that in a list sorted by something like AllianceType, where there are only three -- alliances, the tiebreaker would sort within the "name" key of the table entry. if compareResult == IS_EQUAL_TO then local tiebreaker = sortKeys[sortKey].tiebreaker if tiebreaker then local nextSortOrder if sortKeys[sortKey].tieBreakerSortOrder ~= nil then nextSortOrder = sortKeys[sortKey].tieBreakerSortOrder else nextSortOrder = sortOrder end if sortKeys[sortKey].reverseTiebreakerSortOrder then nextSortOrder = not nextSortOrder end end else if sortOrder == ZO_SORT_ORDER_UP then return compareResult == IS_LESS_THAN end return compareResult == IS_GREATER_THAN end return falseend for i = #t, 1, -1 do t[i] = nil endend t[k] = nil endend--Want to keep ZO_ClearTable(t) snappy, so don't bog it down with an optional callback param to if check t[k] = nil endend dest = dest or {} dest[k] = v end return destend dest = dest or {} dest[k] = v end return destend dest = dest or {} else dest[k] = v end end return destend-- Returns true if table is nil or emptyend-- Returns true if running the iterator once did not return a value. this modifies the iterator. if nextControlValue == nil then return true end return falseend-- The dest table is mutable and will take in the values of all subsequent tables. It must be initialized. local counter = #dest counter = counter + 1 end endend-- The dest table is mutable and will take in the values of all subsequent tables. It must be initialized. end endend return true end end return falseend return index end end return nilend-- Returns true if every argument specified is in the numerically indexed table 't'. for elementIndex = 1, numElements do return false end end return trueend return true end end return falseend-- Returns true if every argument specified is in the non-contiguous table 't'. for elementIndex = 1, numElements do return false end end return trueend return key end end return nilend return true end end return falseendendenddo if i > 1 then i = i - 1 return i, t[i] end end endend local numFilters = filterFunctions and #filterFunctions or 0 if numFilters > 0 then local index = 0 return function() index = index + 1 local passesFilter = true for filterIndex = 1, numFilters do passesFilter = false break end end if passesFilter then else index = index + 1 end end end else endend local numFilters = filterFunctions and #filterFunctions or 0 if numFilters > 0 then return function() while nextKey do local currentKey, currentData = nextKey, nextData local passesFilter = true for filterIndex = 1, numFilters do if not filterFunctions[filterIndex](currentData) then passesFilter = false break end end if passesFilter then return currentKey, currentData end end end else endend local visitedLeft, visitedRight = {}, {} local numVisited = 0 if visitedLeft[left] or visitedRight[right] then return false end visitedLeft[left], visitedRight[right] = true, true numVisited = numVisited + 2 if numVisited > maxTablesVisited then return false end return false end end if left[k] == nil then return false end end return false end return true else return left == right end endend local set = {} end return setend-- Returns true if the two tables contain the same values (using shallow comparison) in the same order. if #left ~= #right then return false end return false end end return trueend-- Returns true if the two tables contain the same values (using shallow comparison) regardless of order. return #left == #right and ZO_AreElementsInNumericallyIndexedTable(left, unpack(right)) and ZO_AreElementsInNumericallyIndexedTable(right, unpack(left))end-- Creates a non-contiguous table, the keys of which are the unique values-- in the numerically indexed table t or, if t is scalar, the value of t. local s = {} if tType == "table" then s[v] = true end elseif tType ~= "nil" then s[t] = true end return send-- Returns a non-contiguous table, the keys of which are the intersecting keys-- shared between the non-contiguous sets s1 and s2. local s = {} if s2[k] then s[k] = true end end return send-- Returns true if the non-contiguous sets s1 and s2 share one or more keys.end-- Returns a non-contiguous table, the keys of which are the intersecting values-- shared between the numerically indexed tables t1 and t2.end-- Returns true if the numerically indexed tables t1 and t2 share one or more values.end-- Returns true if the non-contiguous sets s1 and s2 contain the same keys. if size1 ~= size2 then return false end if not s2[k] then return false end end return trueend local t = {} end return tend local t = {} end return tend |