LCOV - code coverage report
Current view: top level - EnergyPlus - SortAndStringUtilities.cc (source / functions) Hit Total Coverage
Test: lcov.output.filtered Lines: 30 30 100.0 %
Date: 2023-01-17 19:17:23 Functions: 5 5 100.0 %

          Line data    Source code
       1             : // EnergyPlus, Copyright (c) 1996-2023, The Board of Trustees of the University of Illinois,
       2             : // The Regents of the University of California, through Lawrence Berkeley National Laboratory
       3             : // (subject to receipt of any required approvals from the U.S. Dept. of Energy), Oak Ridge
       4             : // National Laboratory, managed by UT-Battelle, Alliance for Sustainable Energy, LLC, and other
       5             : // contributors. All rights reserved.
       6             : //
       7             : // NOTICE: This Software was developed under funding from the U.S. Department of Energy and the
       8             : // U.S. Government consequently retains certain rights. As such, the U.S. Government has been
       9             : // granted for itself and others acting on its behalf a paid-up, nonexclusive, irrevocable,
      10             : // worldwide license in the Software to reproduce, distribute copies to the public, prepare
      11             : // derivative works, and perform publicly and display publicly, and to permit others to do so.
      12             : //
      13             : // Redistribution and use in source and binary forms, with or without modification, are permitted
      14             : // provided that the following conditions are met:
      15             : //
      16             : // (1) Redistributions of source code must retain the above copyright notice, this list of
      17             : //     conditions and the following disclaimer.
      18             : //
      19             : // (2) Redistributions in binary form must reproduce the above copyright notice, this list of
      20             : //     conditions and the following disclaimer in the documentation and/or other materials
      21             : //     provided with the distribution.
      22             : //
      23             : // (3) Neither the name of the University of California, Lawrence Berkeley National Laboratory,
      24             : //     the University of Illinois, U.S. Dept. of Energy nor the names of its contributors may be
      25             : //     used to endorse or promote products derived from this software without specific prior
      26             : //     written permission.
      27             : //
      28             : // (4) Use of EnergyPlus(TM) Name. If Licensee (i) distributes the software in stand-alone form
      29             : //     without changes from the version obtained under this License, or (ii) Licensee makes a
      30             : //     reference solely to the software portion of its product, Licensee must refer to the
      31             : //     software as "EnergyPlus version X" software, where "X" is the version number Licensee
      32             : //     obtained under this License and may not use a different name for the software. Except as
      33             : //     specifically required in this Section (4), Licensee shall not use in a company name, a
      34             : //     product name, in advertising, publicity, or other promotional activities any name, trade
      35             : //     name, trademark, logo, or other designation of "EnergyPlus", "E+", "e+" or confusingly
      36             : //     similar designation, without the U.S. Department of Energy's prior written consent.
      37             : //
      38             : // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
      39             : // IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
      40             : // AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
      41             : // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
      42             : // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
      43             : // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
      44             : // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
      45             : // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
      46             : // POSSIBILITY OF SUCH DAMAGE.
      47             : 
      48             : // C++ Headers
      49             : #include <utility>
      50             : 
      51             : // EnergyPlus Headers
      52             : #include <EnergyPlus/SortAndStringUtilities.hh>
      53             : 
      54             : namespace EnergyPlus {
      55             : 
      56             : namespace SortAndStringUtilities {
      57             : 
      58             :     // Module containing the routines dealing with Sorting
      59             : 
      60             :     // MODULE INFORMATION:
      61             :     //       AUTHOR         Linda Lawrie
      62             :     //       DATE WRITTEN   March 2009
      63             :     //       MODIFIED       na
      64             :     //       RE-ENGINEERED  na
      65             : 
      66             :     // PURPOSE OF THIS MODULE:
      67             :     // <description>
      68             : 
      69             :     // METHODOLOGY EMPLOYED:
      70             :     // <description>
      71             : 
      72             :     // REFERENCES:
      73             :     // na
      74             : 
      75             :     // OTHER NOTES:
      76             :     // na
      77             : 
      78             :     // USE STATEMENTS:
      79             :     // <use statements for data only modules>
      80             :     // <use statements for access to subroutines in other modules>
      81             : 
      82             :     // Data
      83             :     // MODULE PARAMETER DEFINITIONS:
      84             :     // na
      85             : 
      86             :     // DERIVED TYPE DEFINITIONS:
      87             :     // na
      88             : 
      89             :     // MODULE VARIABLE DECLARATIONS:
      90             :     // na
      91             : 
      92             :     // SUBROUTINE SPECIFICATIONS FOR MODULE SortUtilities
      93             : 
      94             :     // Functions
      95             : 
      96        2993 :     void SetupAndSort(Array1D_string &Alphas, // Alphas to be sorted
      97             :                       Array1D_int &iAlphas    // Indexes of sorted array
      98             :     )
      99             :     {
     100             : 
     101             :         // SUBROUTINE INFORMATION:
     102             :         //       AUTHOR         Linda Lawrie
     103             :         //       DATE WRITTEN   March 2009
     104             :         //       MODIFIED       na
     105             :         //       RE-ENGINEERED  na
     106             : 
     107             :         // PURPOSE OF THIS SUBROUTINE:
     108             :         // Set up and call sort routine for Alphas
     109             : 
     110             :         // METHODOLOGY EMPLOYED:
     111             :         // na
     112             : 
     113             :         // REFERENCES:
     114             :         // na
     115             : 
     116             :         // USE STATEMENTS:
     117             :         // na
     118             : 
     119             :         // Argument array dimensioning
     120             : 
     121             :         // Locals
     122             :         // SUBROUTINE ARGUMENT DEFINITIONS:
     123             : 
     124             :         // SUBROUTINE PARAMETER DEFINITIONS:
     125             :         // na
     126             : 
     127             :         // INTERFACE BLOCK SPECIFICATIONS:
     128             :         // na
     129             : 
     130             :         // DERIVED TYPE DEFINITIONS:
     131             :         // na
     132             : 
     133             :         // SUBROUTINE LOCAL VARIABLE DECLARATIONS:
     134             : 
     135      548779 :         for (int Loop = 1, Loop_end = Alphas.u(); Loop <= Loop_end; ++Loop) {
     136      545786 :             iAlphas(Loop) = Loop;
     137             :         }
     138             : 
     139        2993 :         QsortC(Alphas, iAlphas);
     140        2993 :     }
     141             : 
     142     1088583 :     void QsortC(Array1S_string Alphas, // Alphas to be sorted
     143             :                 Array1S_int iAlphas    // Indexes of sorted array
     144             :     )
     145             :     {
     146             : 
     147             :         // SUBROUTINE INFORMATION:
     148             :         //       AUTHOR         Linda Lawrie
     149             :         //       DATE WRITTEN   March 2009
     150             :         //       MODIFIED       na
     151             :         //       RE-ENGINEERED  na
     152             : 
     153             :         // PURPOSE OF THIS SUBROUTINE:
     154             :         // Make sort order for an Alpha Array but store the pointers in an
     155             :         // accompanying integer array which must be filled prior to the first call
     156             :         // as this routine is recursive and called from within.
     157             : 
     158             :         // METHODOLOGY EMPLOYED:
     159             :         // recursion and quick-sort methodology
     160             : 
     161             :         // REFERENCES:
     162             :         // na
     163             : 
     164             :         // USE STATEMENTS:
     165             :         // na
     166             : 
     167             :         // Argument array dimensioning
     168             : 
     169             :         // Locals
     170             :         // SUBROUTINE ARGUMENT DEFINITIONS:
     171             : 
     172             :         // SUBROUTINE PARAMETER DEFINITIONS:
     173             :         // na
     174             : 
     175             :         // INTERFACE BLOCK SPECIFICATIONS:
     176             :         // na
     177             : 
     178             :         // DERIVED TYPE DEFINITIONS:
     179             :         // na
     180             : 
     181             :         // SUBROUTINE LOCAL VARIABLE DECLARATIONS:
     182             : 
     183     1088583 :         if (Alphas.size() > 1) {
     184             :             int iq;
     185      542795 :             QsortPartition(Alphas, iAlphas, iq);
     186      542795 :             QsortC(Alphas({_, iq - 1}), iAlphas({_, iq - 1}));
     187      542795 :             QsortC(Alphas({iq, _}), iAlphas({iq, _}));
     188             :         }
     189     1088583 :     }
     190             : 
     191      542795 :     void QsortPartition(Array1S_string Alphas, // Alphas to be sorted
     192             :                         Array1S_int iAlphas,   // Indexes of sorted array
     193             :                         int &marker)
     194             :     {
     195             : 
     196             :         // SUBROUTINE INFORMATION:
     197             :         //       AUTHOR         Linda Lawrie
     198             :         //       DATE WRITTEN   March 2009
     199             :         //       MODIFIED       na
     200             :         //       RE-ENGINEERED  na
     201             : 
     202             :         // PURPOSE OF THIS SUBROUTINE:
     203             :         // <description>
     204             : 
     205             :         // METHODOLOGY EMPLOYED:
     206             :         // <description>
     207             : 
     208             :         // REFERENCES:
     209             :         // na
     210             : 
     211             :         // Using/Aliasing
     212             : 
     213             :         // Argument array dimensioning
     214             : 
     215             :         // Locals
     216             :         // SUBROUTINE ARGUMENT DEFINITIONS:
     217             : 
     218             :         // SUBROUTINE PARAMETER DEFINITIONS:
     219             :         // na
     220             : 
     221             :         // INTERFACE BLOCK SPECIFICATIONS:
     222             :         // na
     223             : 
     224             :         // DERIVED TYPE DEFINITIONS:
     225             :         // na
     226             : 
     227             :         // SUBROUTINE LOCAL VARIABLE DECLARATIONS:
     228             : 
     229      542795 :         std::string const &cpivot(Alphas(1));
     230      542795 :         int i = 0;
     231      542795 :         int j = Alphas.isize() + 1;
     232             : 
     233             :         while (true) {
     234     2568157 :             --j;
     235             :             while (true) {
     236     9911730 :                 if (lessthani(Alphas(j), cpivot) || equali(Alphas(j), cpivot)) break;
     237     4178127 :                 --j;
     238             :             }
     239     1555476 :             ++i;
     240             :             while (true) {
     241     3400040 :                 if (lessthani(cpivot, Alphas(i)) || equali(cpivot, Alphas(i))) break;
     242      922282 :                 ++i;
     243             :             }
     244     1555476 :             if (i < j) { // Swap the strings at index i and j
     245     1012681 :                 Alphas(i).swap(Alphas(j));
     246     1012681 :                 std::swap(iAlphas(i), iAlphas(j));
     247      542795 :             } else if (i == j) {
     248      171724 :                 marker = i + 1;
     249      171724 :                 return;
     250             :             } else {
     251      371071 :                 marker = i;
     252      371071 :                 return;
     253             :             }
     254             :         }
     255             :     }
     256             : 
     257             : } // namespace SortAndStringUtilities
     258             : 
     259        2313 : } // namespace EnergyPlus

Generated by: LCOV version 1.13