| 1 | /* PermutationInversionCounter_def.h |
| 2 | * |
| 3 | * Copyright (C) 2024-2025 David Weenink |
| 4 | * |
| 5 | * This code is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation; either version 2 of the License, or (at |
| 8 | * your option) any later version. |
| 9 | * |
| 10 | * This code is distributed in the hope that it will be useful, but |
| 11 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | * General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this work. If not, see <http://www.gnu.org/licenses/>. |
| 17 | */ |
| 18 | |
| 19 | #define ooSTRUCT PermutationInversionCounter |
| 20 | oo_DEFINE_CLASS (PermutationInversionCounter, Daata) |
| 21 | |
| 22 | oo_UNSAFE_BORROWED_TRANSIENT_CONST_OBJECT_REFERENCE (Permutation, pdata) |
| 23 | oo_UNSAFE_BORROWED_TRANSIENT_CONST_OBJECT_REFERENCE (Permutation, potherInverse) |
| 24 | oo_OBJECT (Permutation, 0, psortingOrder) |
| 25 | oo_INTEGER (numberOfElements) |
| 26 | oo_INTVEC (workspace, numberOfElements) |
| 27 | oo_INTEGER (totalNumberOfInversions) |
| 28 | oo_INTEGER (totalNumberOfInversionsInInterval) |
| 29 | oo_INTEGER (numberOfInversionsRegistered) |
| 30 | oo_INTEGER (numberOfInversionsToRegister) |
| 31 | oo_INTEGER (posInSortedSelectedInversionIndices) |
| 32 | |
| 33 | #if oo_DECLARING |
| 34 | |
| 35 | INTVEC inversions; // the inversions as pairs of (ilow, ihigh) to be output, link to storage supplied by caller |
| 36 | INTVEC otherInverse; // link to potherInverse -> p.get() supplied by user |
| 37 | |
| 38 | constINTVEC sortedSelectedInversionIndices; // link to storage supplied by caller |
| 39 | |
| 40 | void newData (constPermutation p); |
| 41 | |
| 42 | void reset (); |
| 43 | |
| 44 | integer mergeInversions (integer p, integer q, integer r); |
| 45 | |
| 46 | integer mergeSort (integer p, integer r); |
| 47 | |
| 48 | integer getNumberOfInversions (constPermutation p); |
| 49 | |
| 50 | integer getSelectedInversionsNotInOther ( |
| 51 | constPermutation p, constPermutation otherInverse, constINTVEC const& sortedSelectedInversionIndices, INTVEC const& out_inversions |
| 52 | ); |
| 53 | |
| 54 | integer getSelectedInversions ( |
| 55 | constPermutation p, constINTVEC const& sortedSelectedInversionIndices, INTVEC const& out_inversions |
| 56 | ); |
| 57 | |
| 58 | integer getInversions (constPermutation p, INTVEC const& out_inversions); |
| 59 | |
| 60 | #endif |
| 61 | |
| 62 | #if oo_COPYING |
| 63 | thy inversions = inversions; |
| 64 | thy otherInverse = otherInverse; |
| 65 | thy sortedSelectedInversionIndices = sortedSelectedInversionIndices; |
| 66 | #endif |
| 67 | |
| 68 | oo_END_CLASS (PermutationInversionCounter) |
| 69 | #undef ooSTRUCT |