"Fossies" - the Fresh Open Source Software Archive

Member "xxHash-0.8.0/tests/collisions/sort.cc" (27 Jul 2020, 1785 Bytes) of package /linux/misc/xxHash-0.8.0.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. See also the last Fossies "Diffs" side-by-side code changes report for "sort.cc": 0.7.3_vs_0.7.4.

    1 /*
    2  * sort.cc - C++ sort functions
    3  * Copyright (C) 2019-2020 Yann Collet
    4  * GPL v2 License
    5  *
    6  * This program is free software; you can redistribute it and/or modify
    7  * it under the terms of the GNU General Public License as published by
    8  * the Free Software Foundation; either version 2 of the License, or
    9  * (at your option) any later version.
   10  *
   11  * This program is distributed in the hope that it will be useful,
   12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
   13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   14  * GNU General Public License for more details.
   15  *
   16  * You should have received a copy of the GNU General Public License along
   17  * with this program; if not, write to the Free Software Foundation, Inc.,
   18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
   19  *
   20  * You can contact the author at:
   21  *   - xxHash homepage: https://www.xxhash.com
   22  *   - xxHash source repository: https://github.com/Cyan4973/xxHash
   23  */
   24 
   25 /*
   26  * C++ sort functions tend to run faster than C ones due to templates allowing
   27  * inline optimizations.
   28  * Also, glibc's qsort() seems to inflate memory usage, resulting in OOM
   29  * crashes on the test server.
   30  */
   31 
   32 #include <algorithm>  // std::sort
   33 #define XXH_INLINE_ALL  // XXH128_cmp
   34 #include <xxhash.h>
   35 
   36 #include "sort.hh"
   37 
   38 void sort64(uint64_t* table, size_t size)
   39 {
   40     std::sort(table, table + size);
   41 }
   42 
   43 #include <stdlib.h>  // qsort
   44 
   45 void sort128(XXH128_hash_t* table, size_t size)
   46 {
   47 #if 0
   48     // C++ sort using a custom function object
   49     struct {
   50         bool operator()(XXH128_hash_t a, XXH128_hash_t b) const
   51         {
   52             return XXH128_cmp(&a, &b);
   53         }
   54     } customLess;
   55     std::sort(table, table + size, customLess);
   56 #else
   57     qsort(table, size, sizeof(*table), XXH128_cmp);
   58 #endif
   59 }