LCOV - code coverage report
Current view: top level - home/snapwebsites/snapcpp/snapwebsites/snapdatabase/snapdatabase/bigint - bigint.h (source / functions) Hit Total Coverage
Test: coverage.info Lines: 1 1 100.0 %
Date: 2019-12-15 17:13:15 Functions: 1 1 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : // Copyright (c) 2019  Made to Order Software Corp.  All Rights Reserved
       2             : //
       3             : // https://snapwebsites.org/project/snapdatabase
       4             : // contact@m2osw.com
       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             : #pragma once
      20             : 
      21             : 
      22             : /** \file
      23             :  * \brief Handle a block structure.
      24             :  *
      25             :  * Each block contains a structure. The very first four bytes are always the
      26             :  * magic characters which define the type of the block. The remained of the
      27             :  * block is a _lose_ structure which very often changes in size because it
      28             :  * includes parameters such as a string or an array.
      29             :  *
      30             :  * Also in most cases arrays are also themselvess _lose_ structures (a few
      31             :  * are just numbers such as column ids or block references.)
      32             :  *
      33             :  * IMPORTANT: The types defined here are also the types that we accept in
      34             :  * a user table. Here we define structures and later tables.
      35             :  */
      36             : 
      37             : // C++ lib
      38             : //
      39             : #include    <cstdint>
      40             : #include    <initializer_list>
      41             : 
      42             : 
      43             : 
      44             : namespace snapdatabase
      45             : {
      46             : 
      47             : 
      48             : 
      49             : 
      50             : 
      51             : void                                add128(std::uint64_t * dst, std::uint64_t const * src);
      52             : void                                add256(std::uint64_t * dst, std::uint64_t const * src);
      53             : void                                add512(std::uint64_t * dst, std::uint64_t const * src);
      54             : 
      55             : void                                sub128(std::uint64_t * dst, std::uint64_t const * src);
      56             : void                                sub256(std::uint64_t * dst, std::uint64_t const * src);
      57             : void                                sub512(std::uint64_t * dst, std::uint64_t const * src);
      58             : 
      59             : 
      60             : struct uint512_t;
      61             : 
      62             : struct int512_t
      63             : {
      64             :                                     int512_t();
      65             :                                     int512_t(int512_t const & rhs);
      66             :                                     int512_t(uint512_t const & rhs);
      67             :                                     int512_t(std::initializer_list<std::uint64_t> rhs);
      68             : 
      69             :     bool                            is_positive() const { return f_high_value >= 0; }
      70     1038887 :     bool                            is_negative() const { return f_high_value < 0; }
      71             : 
      72             :     std::size_t                     bit_size() const;
      73             : 
      74             :     int512_t                        operator - () const;
      75             :     int512_t &                      operator += (int512_t const & rhs);
      76             :     int512_t &                      operator -= (int512_t const & rhs);
      77             : 
      78             :     std::uint64_t                   f_value[7] = { 0 };
      79             :     std::int64_t                    f_high_value = 0;
      80             : };
      81             : 
      82             : 
      83             : struct uint512_t
      84             : {
      85             :                                     uint512_t();
      86             :                                     uint512_t(uint512_t const & rhs);
      87             :                                     uint512_t(int512_t const & rhs);
      88             :                                     uint512_t(std::initializer_list<std::uint64_t> rhs);
      89             : 
      90             :     uint512_t &                     operator = (uint512_t const & rhs);
      91             :     uint512_t &                     operator = (int512_t const & rhs);
      92             : 
      93             :     bool                            is_positive() const { return true; }
      94             :     bool                            is_negative() const { return false; }
      95             : 
      96             :     std::size_t                     bit_size() const;
      97             :     void                            lsl(int count);
      98             :     void                            lsr(int count);
      99             :     bool                            is_zero() const;
     100             :     int                             compare(uint512_t const & rhs) const;
     101             :     uint512_t &                     div(uint512_t const & rhs, uint512_t & remainder);
     102             : 
     103             :     uint512_t                       operator - () const;
     104             :     uint512_t &                     operator += (uint512_t const & rhs);
     105             :     uint512_t &                     operator -= (uint512_t const & rhs);
     106             :     uint512_t &                     operator *= (uint512_t const & rhs);
     107             : 
     108             :     bool                            operator == (uint64_t rhs) const;
     109             :     bool                            operator != (uint64_t rhs) const;
     110             : 
     111             :     std::uint64_t                   f_value[8] = { 0 };
     112             : };
     113             : 
     114             : 
     115             : 
     116             : 
     117             : } // namespace snapdatabase
     118             : // vim: ts=4 sw=4 et

Generated by: LCOV version 1.13