Loading [MathJax]/extensions/tex2jax.js
MRFFL: MR Fortran Finance Library 2024-12-28
Computational Tools For Finance
All Namespaces Files Functions Variables
mrffl_bitset.f90
Go to the documentation of this file.
1! -*- Mode:F90; Coding:us-ascii-unix; fill-column:129 -*-
2!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!.H.S.!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!.H.E.!!
3!>
4!! @file mrffl_bitset.f90
5!! @author Mitch Richling http://www.mitchr.me/
6!! @date 2025-01-02
7!! @brief Simple sets (using the bits of an integer to indicate element existence).@EOL
8!! @keywords finance fortran monte carlo inflation cashflow time value of money tvm percentages taxes stock market
9!! @std F2023
10!! @see https://github.com/richmit/FortranFinance
11!! @copyright
12!! @parblock
13!! Copyright (c) 2025, Mitchell Jay Richling <http://www.mitchr.me/> All rights reserved.
14!!
15!! Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following
16!! conditions are met:
17!!
18!! 1. Redistributions of source code must retain the above copyright notice, this list of conditions, and the following
19!! disclaimer.
20!!
21!! 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions, and the following
22!! disclaimer in the documentation and/or other materials provided with the distribution.
23!!
24!! 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products
25!! derived from this software without specific prior written permission.
26!!
27!! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
28!! INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
29!! DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30!! EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
31!! USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32!! LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
33!! OF THE POSSIBILITY OF SUCH DAMAGE.
34!! @endparblock
35!!
36
37!----------------------------------------------------------------------------------------------------------------------------------
38!> Simple sets (using the bits of an integer to indicate element existence).
39!!
40!! This is *NOT* a compete implementation of bitsets. Just what we need for MRFFL. Today bitsets are used to identity
41!! unknown variables for TVM solvers, and elements to print in output routines.
42!!
44 use mrffl_config, only: ik=>mrfflik
45 implicit none
46 private
47
49
50contains
51
52 !------------------------------------------------------------------------------------------------------------------------------
53 !> Return the number of elements in bitset.
54 !!
55 integer(kind=ik) pure function bitset_size(bitset)
56 integer(kind=ik), intent(in) :: bitset
57 bitset_size = int(popcnt(bitset), kind=ik)
58 end function bitset_size
59
60 !------------------------------------------------------------------------------------------------------------------------------
61 !> Return the set diffrence between bitset1 and bitset2.
62 !!
63 integer(kind=ik) pure function bitset_minus(bitset1, bitset2)
64 integer(kind=ik), intent(in) :: bitset1, bitset2
65 bitset_minus = iand(bitset1, not(bitset2))
66 end function bitset_minus
67
68 !------------------------------------------------------------------------------------------------------------------------------
69 !!> Return .true. if bitset1 is a subset of bitset2, and .false. otherwise.
70 !!
71 logical pure function bitset_subsetp(bitset1, bitset2)
72 integer(kind=ik), intent(in) :: bitset1, bitset2
73 bitset_subsetp = (iand(bitset1, bitset2) == bitset1)
74 end function bitset_subsetp
75
76 !------------------------------------------------------------------------------------------------------------------------------
77 !!> Return .true. if bitset1 is NOT a subset of bitset2, and .false. otherwise.
78 !!
79 logical pure function bitset_not_subsetp(bitset1, bitset2)
80 integer(kind=ik), intent(in) :: bitset1, bitset2
81 bitset_not_subsetp = (iand(bitset1, bitset2) /= bitset1)
82 end function bitset_not_subsetp
83
84 !------------------------------------------------------------------------------------------------------------------------------
85 !!> Return .true. if bitset1 and bitset2 have a non-empty intersection, and .false. otherwise.
86 !!
87 logical pure function bitset_intersectp(bitset1, bitset2)
88 integer(kind=ik), intent(in) :: bitset1, bitset2
89 bitset_intersectp = (iand(bitset1, bitset2) /= 0_ik)
90 end function bitset_intersectp
91
92 !------------------------------------------------------------------------------------------------------------------------------
93 !!> Return .true. if bitset1 and bitset2 have an empty intersection, and .false. otherwise.
94 !!
95 logical pure function bitset_not_intersectp(bitset1, bitset2)
96 integer(kind=ik), intent(in) :: bitset1, bitset2
97 bitset_not_intersectp = (iand(bitset1, bitset2) == 0_ik)
98 end function bitset_not_intersectp
99
100end module mrffl_bitset
Simple sets (using the bits of an integer to indicate element existence).
logical pure function, public bitset_intersectp(bitset1, bitset2)
integer(kind=ik) pure function, public bitset_size(bitset)
Return the number of elements in bitset.
logical pure function, public bitset_not_intersectp(bitset1, bitset2)
integer(kind=ik) pure function, public bitset_minus(bitset1, bitset2)
Return the set diffrence between bitset1 and bitset2.
logical pure function, public bitset_not_subsetp(bitset1, bitset2)
logical pure function, public bitset_subsetp(bitset1, bitset2)
Configuration for MRFFL (MR Fortran Finance Library).
integer, parameter, public mrfflik
Integer kinds used in interfaces.