001/* 002 * $Id: ExpVectorByte.java 4270 2012-10-24 20:41:11Z kredel $ 003 */ 004 005package edu.jas.poly; 006 007 008import java.util.List; 009import java.util.ArrayList; 010 011 012/** 013 * ExpVectorByte implements exponent vectors for polynomials using arrays of 014 * byte as storage unit. This class is used by ExpVector internally, there is no 015 * need to use this class directly. 016 * @see ExpVector 017 * @author Heinz Kredel 018 */ 019 020public final class ExpVectorByte extends ExpVector 021/*implements AbelianGroupElem<ExpVectorByte>*/{ 022 023 024 /** 025 * The data structure is an array of longs. 026 */ 027 /*package*/final byte[] val; 028 029 030 /** 031 * Largest byte. 032 */ 033 public static final long maxByte = (long) Byte.MAX_VALUE / 2; 034 035 036 /** 037 * Smallest byte. 038 */ 039 public static final long minByte = (long) Byte.MIN_VALUE / 2; 040 041 042 /** 043 * Constructor for ExpVector. 044 * @param n length of exponent vector. 045 */ 046 public ExpVectorByte(int n) { 047 this(new byte[n]); 048 } 049 050 051 /** 052 * Constructor for ExpVector. Sets exponent i to e. 053 * @param n length of exponent vector. 054 * @param i index of exponent to be set. 055 * @param e exponent to be set. 056 */ 057 public ExpVectorByte(int n, int i, byte e) { 058 this(n); 059 val[i] = e; 060 } 061 062 063 /** 064 * Constructor for ExpVector. Sets exponent i to e. 065 * @param n length of exponent vector. 066 * @param i index of exponent to be set. 067 * @param e exponent to be set. 068 */ 069 public ExpVectorByte(int n, int i, long e) { 070 this(n); 071 if (e >= maxByte || e <= minByte) { 072 throw new IllegalArgumentException("exponent to large: " + e); 073 } 074 val[i] = (byte) e; 075 } 076 077 078 /** 079 * Internal constructor for ExpVector. Sets val. 080 * @param v internal representation array. 081 */ 082 protected ExpVectorByte(byte[] v) { 083 super(); 084 val = v; 085 } 086 087 088 /** 089 * Constructor for ExpVector. Sets val, converts from long array. 090 * @param v long representation array. 091 */ 092 public ExpVectorByte(long[] v) { 093 this(v.length); 094 for (int i = 0; i < v.length; i++) { 095 if (v[i] >= maxByte || v[i] <= minByte) { 096 throw new IllegalArgumentException("exponent to large: " + v[i]); 097 } 098 val[i] = (byte) v[i]; 099 } 100 } 101 102 103 /** 104 * Constructor for ExpVector. Converts a String representation to an 105 * ExpVector. Accepted format = (1,2,3,4,5,6,7). 106 * @param s String representation. 107 */ 108 public ExpVectorByte(String s) throws NumberFormatException { 109 super(); 110 // first format = (1,2,3,4,5,6,7) 111 List<Byte> exps = new ArrayList<Byte>(); 112 s = s.trim(); 113 int b = s.indexOf('('); 114 int e = s.indexOf(')', b + 1); 115 String teil; 116 int k; 117 byte a; 118 if (b >= 0 && e >= 0) { 119 b++; 120 while ((k = s.indexOf(',', b)) >= 0) { 121 teil = s.substring(b, k); 122 a = Byte.parseByte(teil); 123 exps.add(Byte.valueOf(a)); 124 b = k + 1; 125 } 126 if (b <= e) { 127 teil = s.substring(b, e); 128 a = Byte.parseByte(teil); 129 exps.add(Byte.valueOf(a)); 130 } 131 int length = exps.size(); 132 val = new byte[length]; 133 for (int j = 0; j < length; j++) { 134 val[j] = exps.get(j).byteValue(); 135 } 136 } else { 137 // not implemented 138 val = null; 139 // length = -1; 140 //Vector names = new Vector(); 141 //vars = s; 142 } 143 } 144 145 146 /** 147 * Clone this. 148 * @see java.lang.Object#clone() 149 */ 150 @Override 151 public ExpVectorByte copy() { 152 byte[] w = new byte[val.length]; 153 System.arraycopy(val, 0, w, 0, val.length); 154 return new ExpVectorByte(w); 155 } 156 157 158 /** 159 * Get the exponent vector. 160 * @return val as long. 161 */ 162 @Override 163 /*package*/long[] getVal() { 164 long v[] = new long[val.length]; 165 for (int i = 0; i < val.length; i++) { 166 v[i] = val[i]; 167 } 168 return v; 169 } 170 171 172 /** 173 * Get the exponent at position i. 174 * @param i position. 175 * @return val[i]. 176 */ 177 @Override 178 public long getVal(int i) { 179 return val[i]; 180 } 181 182 183 /** 184 * Set the exponent at position i to e. 185 * @param i 186 * @param e 187 * @return old val[i]. 188 */ 189 @Override 190 protected long setVal(int i, long e) { 191 byte x = val[i]; 192 if (e >= maxByte || e <= minByte) { 193 throw new IllegalArgumentException("exponent to large: " + e); 194 } 195 val[i] = (byte) e; 196 hash = 0; // beware of race condition 197 return x; 198 } 199 200 201 /** 202 * Set the exponent at position i to e. 203 * @param i 204 * @param e 205 * @return old val[i]. 206 */ 207 protected byte setVal(int i, byte e) { 208 byte x = val[i]; 209 val[i] = e; 210 hash = 0; // beware of race condition 211 return x; 212 } 213 214 215 /** 216 * Get the length of this exponent vector. 217 * @return val.length. 218 */ 219 @Override 220 public int length() { 221 return val.length; 222 } 223 224 225 /** 226 * Extend variables. Used e.g. in module embedding. Extend this by i 227 * elements and set val[j] to e. 228 * @param i number of elements to extend. 229 * @param j index of element to be set. 230 * @param e new exponent for val[j]. 231 * @return extended exponent vector. 232 */ 233 @Override 234 public ExpVectorByte extend(int i, int j, long e) { 235 byte[] w = new byte[val.length + i]; 236 System.arraycopy(val, 0, w, i, val.length); 237 if (j >= i) { 238 throw new IllegalArgumentException("i " + i + " <= j " + j + " invalid"); 239 } 240 if (e >= maxByte || e <= minByte) { 241 throw new IllegalArgumentException("exponent to large: " + e); 242 } 243 w[j] = (byte) e; 244 return new ExpVectorByte(w); 245 } 246 247 248 /** 249 * Extend lower variables. Extend this by i lower elements and set val[j] to 250 * e. 251 * @param i number of elements to extend. 252 * @param j index of element to be set. 253 * @param e new exponent for val[j]. 254 * @return extended exponent vector. 255 */ 256 @Override 257 public ExpVectorByte extendLower(int i, int j, long e) { 258 byte[] w = new byte[val.length + i]; 259 System.arraycopy(val, 0, w, 0, val.length); 260 if (j >= i) { 261 throw new IllegalArgumentException("i " + i + " <= j " + j + " invalid"); 262 } 263 w[val.length + j] = (byte) e; 264 return new ExpVectorByte(w); 265 } 266 267 268 /** 269 * Contract variables. Used e.g. in module embedding. Contract this to len 270 * elements. 271 * @param i position of first element to be copied. 272 * @param len new length. 273 * @return contracted exponent vector. 274 */ 275 @Override 276 public ExpVectorByte contract(int i, int len) { 277 if (i + len > val.length) { 278 throw new IllegalArgumentException("len " + len + " > val.len " + val.length); 279 } 280 byte[] w = new byte[len]; 281 System.arraycopy(val, i, w, 0, len); 282 return new ExpVectorByte(w); 283 } 284 285 286 /** 287 * Reverse variables. Used e.g. in opposite rings. 288 * @return reversed exponent vector. 289 */ 290 @Override 291 public ExpVectorByte reverse() { 292 byte[] w = new byte[val.length]; 293 for (int i = 0; i < val.length; i++) { 294 w[i] = val[val.length - 1 - i]; 295 } 296 return new ExpVectorByte(w); 297 } 298 299 300 /** 301 * Reverse j variables. Used e.g. in opposite rings. Reverses the first j-1 302 * variables, the rest is unchanged. 303 * @param j index of first variable not reversed. 304 * @return reversed exponent vector. 305 */ 306 @Override 307 public ExpVectorByte reverse(int j) { 308 if (j <= 0 || j > val.length) { 309 return this; 310 } 311 byte[] w = new byte[val.length]; 312 for (int i = 0; i < j; i++) { 313 w[i] = val[j - 1 - i]; 314 } 315 // copy rest 316 for (int i = j; i < val.length; i++) { 317 w[i] = val[i]; 318 } 319 return new ExpVectorByte(w); 320 } 321 322 323 /** 324 * Combine with ExpVector. Combine this with the other ExpVector V. 325 * @param V the other exponent vector. 326 * @return combined exponent vector. 327 */ 328 @Override 329 public ExpVectorByte combine(ExpVector V) { 330 if (V == null || V.length() == 0) { 331 return this; 332 } 333 ExpVectorByte Vi = (ExpVectorByte) V; 334 if (val.length == 0) { 335 return Vi; 336 } 337 byte[] w = new byte[val.length + Vi.val.length]; 338 System.arraycopy(val, 0, w, 0, val.length); 339 System.arraycopy(Vi.val, 0, w, val.length, Vi.val.length); 340 return new ExpVectorByte(w); 341 } 342 343 344 /** 345 * Get the string representation. 346 * @see java.lang.Object#toString() 347 */ 348 @Override 349 public String toString() { 350 return super.toString() + ":byte"; 351 } 352 353 354 /** 355 * Comparison with any other object. 356 * @see java.lang.Object#equals(java.lang.Object) 357 */ 358 @Override 359 public boolean equals(Object B) { 360 if (!(B instanceof ExpVectorByte)) { 361 return false; 362 } 363 ExpVectorByte b = (ExpVectorByte) B; 364 int t = this.invLexCompareTo(b); 365 //System.out.println("equals: this = " + this + " B = " + B + " t = " + t); 366 return (0 == t); 367 } 368 369 370 /** 371 * hashCode for this exponent vector. 372 * @see java.lang.Object#hashCode() Only for findbugs. 373 */ 374 @Override 375 public int hashCode() { 376 return super.hashCode(); 377 } 378 379 380 /** 381 * ExpVector absolute value. 382 * @return abs(this). 383 */ 384 @Override 385 public ExpVectorByte abs() { 386 byte[] u = val; 387 byte[] w = new byte[u.length]; 388 for (int i = 0; i < u.length; i++) { 389 if (u[i] >= 0L) { 390 w[i] = u[i]; 391 } else { 392 w[i] = (byte) (-u[i]); 393 } 394 } 395 return new ExpVectorByte(w); 396 //return EVABS(this); 397 } 398 399 400 /** 401 * ExpVector negate. 402 * @return -this. 403 */ 404 @Override 405 public ExpVectorByte negate() { 406 byte[] u = val; 407 byte[] w = new byte[u.length]; 408 for (int i = 0; i < u.length; i++) { 409 w[i] = (byte) (-u[i]); 410 } 411 return new ExpVectorByte(w); 412 // return EVNEG(this); 413 } 414 415 416 /** 417 * ExpVector summation. 418 * @param V 419 * @return this+V. 420 */ 421 @Override 422 public ExpVectorByte sum(ExpVector V) { 423 byte[] u = val; 424 byte[] v = ((ExpVectorByte) V).val; 425 byte[] w = new byte[u.length]; 426 for (int i = 0; i < u.length; i++) { 427 w[i] = (byte) (u[i] + v[i]); 428 } 429 return new ExpVectorByte(w); 430 // return EVSUM(this, V); 431 } 432 433 434 /** 435 * ExpVector subtract. Result may have negative entries. 436 * @param V 437 * @return this-V. 438 */ 439 @Override 440 public ExpVectorByte subtract(ExpVector V) { 441 byte[] u = val; 442 byte[] v = ((ExpVectorByte) V).val; 443 byte[] w = new byte[u.length]; 444 for (int i = 0; i < u.length; i++) { 445 w[i] = (byte) (u[i] - v[i]); 446 } 447 return new ExpVectorByte(w); 448 //return EVDIF(this, V); 449 } 450 451 452 /** 453 * ExpVector substitution. Clone and set exponent to d at position i. 454 * @param i position. 455 * @param d new exponent. 456 * @return substituted ExpVector. 457 */ 458 public ExpVectorByte subst(int i, byte d) { 459 ExpVectorByte V = this.copy(); 460 @SuppressWarnings("unused") 461 long e = V.setVal(i, d); 462 return V; 463 //return EVSU(this, i, d); 464 } 465 466 467 /** 468 * ExpVector substitution. Clone and set exponent to d at position i. 469 * @param i position. 470 * @param d new exponent. 471 * @return substituted ExpVector. 472 */ 473 @Override 474 public ExpVectorByte subst(int i, long d) { 475 ExpVectorByte V = this.copy(); 476 @SuppressWarnings("unused") 477 long e = V.setVal(i, d); 478 return V; 479 //return EVSU(this, i, d); 480 } 481 482 483 /** 484 * ExpVector signum. 485 * @return 0 if this is zero, -1 if some entry is negative, 1 if no entry is 486 * negative and at least one entry is positive. 487 */ 488 @Override 489 public int signum() { 490 int t = 0; 491 byte[] u = val; 492 for (int i = 0; i < u.length; i++) { 493 if (u[i] < 0) { 494 return -1; 495 } 496 if (u[i] > 0) { 497 t = 1; 498 } 499 } 500 return t; 501 //return EVSIGN(this); 502 } 503 504 505 /** 506 * ExpVector total degree. 507 * @return sum of all exponents. 508 */ 509 @Override 510 public long totalDeg() { 511 long t = 0; 512 byte[] u = val; // U.val; 513 for (int i = 0; i < u.length; i++) { 514 t += u[i]; 515 } 516 return t; 517 //return EVTDEG(this); 518 } 519 520 521 /** 522 * ExpVector maximal degree. 523 * @return maximal exponent. 524 */ 525 @Override 526 public long maxDeg() { 527 long t = 0; 528 byte[] u = val; 529 for (int i = 0; i < u.length; i++) { 530 if (u[i] > t) { 531 t = u[i]; 532 } 533 } 534 return t; 535 //return EVMDEG(this); 536 } 537 538 539 /** 540 * ExpVector weighted degree. 541 * @param w weights. 542 * @return weighted sum of all exponents. 543 */ 544 @Override 545 public long weightDeg(long[][] w) { 546 if (w == null || w.length == 0) { 547 return totalDeg(); // assume weight 1 548 } 549 long t = 0; 550 byte[] u = val; 551 for (int j = 0; j < w.length; j++) { 552 long[] wj = w[j]; 553 for (int i = 0; i < u.length; i++) { 554 t += wj[i] * u[i]; 555 } 556 } 557 return t; 558 //return EVWDEG( w, this ); 559 } 560 561 562 /** 563 * ExpVector least common multiple. 564 * @param V 565 * @return component wise maximum of this and V. 566 */ 567 @Override 568 public ExpVectorByte lcm(ExpVector V) { 569 byte[] u = val; 570 byte[] v = ((ExpVectorByte) V).val; 571 byte[] w = new byte[u.length]; 572 for (int i = 0; i < u.length; i++) { 573 w[i] = (u[i] >= v[i] ? u[i] : v[i]); 574 } 575 return new ExpVectorByte(w); 576 //return EVLCM(this, V); 577 } 578 579 580 /** 581 * ExpVector greatest common divisor. 582 * @param V 583 * @return component wise minimum of this and V. 584 */ 585 @Override 586 public ExpVectorByte gcd(ExpVector V) { 587 byte[] u = val; 588 byte[] v = ((ExpVectorByte) V).val; 589 byte[] w = new byte[u.length]; 590 for (int i = 0; i < u.length; i++) { 591 w[i] = (u[i] <= v[i] ? u[i] : v[i]); 592 } 593 return new ExpVectorByte(w); 594 //return EVGCD(this, V); 595 } 596 597 598 /** 599 * ExpVector dependency on variables. 600 * @return array of indices where val has positive exponents. 601 */ 602 @Override 603 public int[] dependencyOnVariables() { 604 byte[] u = val; 605 int l = 0; 606 for (int i = 0; i < u.length; i++) { 607 if (u[i] > 0) { 608 l++; 609 } 610 } 611 int[] dep = new int[l]; 612 if (l == 0) { 613 return dep; 614 } 615 int j = 0; 616 for (int i = 0; i < u.length; i++) { 617 if (u[i] > 0) { 618 dep[j] = i; 619 j++; 620 } 621 } 622 return dep; 623 } 624 625 626 /** 627 * ExpVector multiple test. Test if this is component wise greater or equal 628 * to V. 629 * @param V 630 * @return true if this is a multiple of V, else false. 631 */ 632 @Override 633 public boolean multipleOf(ExpVector V) { 634 byte[] u = val; 635 byte[] v = ((ExpVectorByte) V).val; 636 boolean t = true; 637 for (int i = 0; i < u.length; i++) { 638 if (u[i] < v[i]) { 639 return false; 640 } 641 } 642 return t; 643 //return EVMT(this, V); 644 } 645 646 647 /** 648 * ExpVector compareTo. 649 * @param V 650 * @return 0 if U == V, -1 if U < V, 1 if U > V. 651 */ 652 @Override 653 public int compareTo(ExpVector V) { 654 return this.invLexCompareTo(V); 655 } 656 657 658 /** 659 * ExpVector inverse lexicographical compareTo. 660 * @param V 661 * @return 0 if U == V, -1 if U < V, 1 if U > V. 662 */ 663 @Override 664 public int invLexCompareTo(ExpVector V) { 665 byte[] u = val; 666 byte[] v = ((ExpVectorByte) V).val; 667 int t = 0; 668 for (int i = 0; i < u.length; i++) { 669 if (u[i] > v[i]) 670 return 1; 671 if (u[i] < v[i]) 672 return -1; 673 } 674 return t; 675 //return EVILCP(this, V); 676 } 677 678 679 /** 680 * ExpVector inverse lexicographical compareTo. 681 * @param V 682 * @param begin 683 * @param end 684 * @return 0 if U == V, -1 if U < V, 1 if U > V. 685 */ 686 @Override 687 public int invLexCompareTo(ExpVector V, int begin, int end) { 688 byte[] u = val; 689 byte[] v = ((ExpVectorByte) V).val; 690 int t = 0; 691 for (int i = begin; i < end; i++) { 692 if (u[i] > v[i]) 693 return 1; 694 if (u[i] < v[i]) 695 return -1; 696 } 697 return t; 698 //return EVILCP(this, V, begin, end); 699 } 700 701 702 /** 703 * ExpVector inverse graded lexicographical compareTo. 704 * @param V 705 * @return 0 if U == V, -1 if U < V, 1 if U > V. 706 */ 707 @Override 708 public int invGradCompareTo(ExpVector V) { 709 byte[] u = val; 710 byte[] v = ((ExpVectorByte) V).val; 711 int t = 0; 712 int i; 713 for (i = 0; i < u.length; i++) { 714 if (u[i] > v[i]) { 715 t = 1; 716 break; 717 } 718 if (u[i] < v[i]) { 719 t = -1; 720 break; 721 } 722 } 723 if (t == 0) { 724 return t; 725 } 726 long up = 0; 727 long vp = 0; 728 for (int j = i; j < u.length; j++) { 729 up += u[j]; 730 vp += v[j]; 731 } 732 if (up > vp) { 733 t = 1; 734 } else { 735 if (up < vp) { 736 t = -1; 737 } 738 } 739 return t; 740 //return EVIGLC(this, V); 741 } 742 743 744 /** 745 * ExpVector inverse graded lexicographical compareTo. 746 * @param V 747 * @param begin 748 * @param end 749 * @return 0 if U == V, -1 if U < V, 1 if U > V. 750 */ 751 @Override 752 public int invGradCompareTo(ExpVector V, int begin, int end) { 753 byte[] u = val; 754 byte[] v = ((ExpVectorByte) V).val; 755 int t = 0; 756 int i; 757 for (i = begin; i < end; i++) { 758 if (u[i] > v[i]) { 759 t = 1; 760 break; 761 } 762 if (u[i] < v[i]) { 763 t = -1; 764 break; 765 } 766 } 767 if (t == 0) { 768 return t; 769 } 770 long up = 0; 771 long vp = 0; 772 for (int j = i; j < end; j++) { 773 up += u[j]; 774 vp += v[j]; 775 } 776 if (up > vp) { 777 t = 1; 778 } else { 779 if (up < vp) { 780 t = -1; 781 } 782 } 783 return t; 784 //return EVIGLC(this, V, begin, end); 785 } 786 787 788 /** 789 * ExpVector reverse inverse lexicographical compareTo. 790 * @param V 791 * @return 0 if U == V, -1 if U < V, 1 if U > V. 792 */ 793 @Override 794 public int revInvLexCompareTo(ExpVector V) { 795 byte[] u = val; 796 byte[] v = ((ExpVectorByte) V).val; 797 int t = 0; 798 for (int i = u.length - 1; i >= 0; i--) { 799 if (u[i] > v[i]) 800 return 1; 801 if (u[i] < v[i]) 802 return -1; 803 } 804 return t; 805 //return EVRILCP(this, V); 806 } 807 808 809 /** 810 * ExpVector reverse inverse lexicographical compareTo. 811 * @param V 812 * @param begin 813 * @param end 814 * @return 0 if U == V, -1 if U < V, 1 if U > V. 815 */ 816 @Override 817 public int revInvLexCompareTo(ExpVector V, int begin, int end) { 818 byte[] u = val; 819 byte[] v = ((ExpVectorByte) V).val; 820 int t = 0; 821 for (int i = end - 1; i >= begin; i--) { 822 if (u[i] > v[i]) 823 return 1; 824 if (u[i] < v[i]) 825 return -1; 826 } 827 return t; 828 //return EVRILCP(this, V, begin, end); 829 } 830 831 832 /** 833 * ExpVector reverse inverse graded compareTo. 834 * @param V 835 * @return 0 if U == V, -1 if U < V, 1 if U > V. 836 */ 837 @Override 838 public int revInvGradCompareTo(ExpVector V) { 839 byte[] u = val; 840 byte[] v = ((ExpVectorByte) V).val; 841 int t = 0; 842 int i; 843 for (i = u.length - 1; i >= 0; i--) { 844 if (u[i] > v[i]) { 845 t = 1; 846 break; 847 } 848 if (u[i] < v[i]) { 849 t = -1; 850 break; 851 } 852 } 853 if (t == 0) { 854 return t; 855 } 856 long up = 0; 857 long vp = 0; 858 for (int j = i; j >= 0; j--) { 859 up += u[j]; 860 vp += v[j]; 861 } 862 if (up > vp) { 863 t = 1; 864 } else { 865 if (up < vp) { 866 t = -1; 867 } 868 } 869 return t; 870 //return EVRIGLC(this, V); 871 } 872 873 874 /** 875 * ExpVector reverse inverse graded compareTo. 876 * @param V 877 * @param begin 878 * @param end 879 * @return 0 if U == V, -1 if U < V, 1 if U > V. 880 */ 881 @Override 882 public int revInvGradCompareTo(ExpVector V, int begin, int end) { 883 byte[] u = val; 884 byte[] v = ((ExpVectorByte) V).val; 885 int t = 0; 886 int i; 887 for (i = end - 1; i >= begin; i--) { 888 if (u[i] > v[i]) { 889 t = 1; 890 break; 891 } 892 if (u[i] < v[i]) { 893 t = -1; 894 break; 895 } 896 } 897 if (t == 0) { 898 return t; 899 } 900 long up = 0; 901 long vp = 0; 902 for (int j = i; j >= begin; j--) { 903 up += u[j]; 904 vp += v[j]; 905 } 906 if (up > vp) { 907 t = 1; 908 } else { 909 if (up < vp) { 910 t = -1; 911 } 912 } 913 return t; 914 //return EVRIGLC(this, V, begin, end); 915 } 916 917 918 /** 919 * ExpVector inverse weighted lexicographical compareTo. 920 * @param w weight array. 921 * @param V 922 * @return 0 if U == V, -1 if U < V, 1 if U > V. 923 */ 924 @Override 925 public int invWeightCompareTo(long[][] w, ExpVector V) { 926 byte[] u = val; 927 byte[] v = ((ExpVectorByte) V).val; 928 int t = 0; 929 int i; 930 for (i = 0; i < u.length; i++) { 931 if (u[i] > v[i]) { 932 t = 1; 933 break; 934 } 935 if (u[i] < v[i]) { 936 t = -1; 937 break; 938 } 939 } 940 if (t == 0) { 941 return t; 942 } 943 for (int k = 0; k < w.length; k++) { 944 long[] wk = w[k]; 945 long up = 0; 946 long vp = 0; 947 for (int j = i; j < u.length; j++) { 948 up += wk[j] * u[j]; 949 vp += wk[j] * v[j]; 950 } 951 if (up > vp) { 952 return 1; 953 } else if (up < vp) { 954 return -1; 955 } 956 } 957 return t; 958 //return EVIWLC(w, this, V); 959 } 960 961 962 /** 963 * ExpVector inverse weighted lexicographical compareTo. 964 * @param w weight array. 965 * @param V 966 * @param begin 967 * @param end 968 * @return 0 if U == V, -1 if U < V, 1 if U > V. 969 */ 970 @Override 971 public int invWeightCompareTo(long[][] w, ExpVector V, int begin, int end) { 972 byte[] u = val; 973 byte[] v = ((ExpVectorByte) V).val; 974 int t = 0; 975 int i; 976 for (i = begin; i < end; i++) { 977 if (u[i] > v[i]) { 978 t = 1; 979 break; 980 } 981 if (u[i] < v[i]) { 982 t = -1; 983 break; 984 } 985 } 986 if (t == 0) { 987 return t; 988 } 989 for (int k = 0; k < w.length; k++) { 990 long[] wk = w[k]; 991 long up = 0; 992 long vp = 0; 993 for (int j = i; j < end; j++) { 994 up += wk[j] * u[j]; 995 vp += wk[j] * v[j]; 996 } 997 if (up > vp) { 998 return 1; 999 } else if (up < vp) { 1000 return -1; 1001 } 1002 } 1003 return t; 1004 //return EVIWLC(w, this, V, begin, end); 1005 } 1006 1007}