bitset_type Derived Type

type, public, abstract :: bitset_type

Parent type for bitset_64 and bitset_large (Specification)


Contents

Source Code


Type-Bound Procedures

procedure(all_abstract), public, deferred, pass(self) :: all

  • elemental function all_abstract(self) result(all)Prototype

    Returns .true. if all bits in self are 1, .false. otherwise.

    Read more…

    Arguments

    TypeIntentOptionalAttributesName
    class(bitset_type), intent(in) :: self

    Return Value logical

procedure(any_abstract), public, deferred, pass(self) :: any

  • elemental function any_abstract(self) result(any)Prototype

    Returns .true. if any bit in self is 1, .false. otherwise.

    Read more…

    Arguments

    TypeIntentOptionalAttributesName
    class(bitset_type), intent(in) :: self

    Return Value logical

procedure(bit_count_abstract), public, deferred, pass(self) :: bit_count

  • elemental function bit_count_abstract(self) result(bit_count)Prototype

    Returns the number of non-zero bits in self.

    Read more…

    Arguments

    TypeIntentOptionalAttributesName
    class(bitset_type), intent(in) :: self

    Return Value integer(kind=bits_kind)

procedure, public, pass(self) :: bits

  • public elemental function bits(self)

    License
    Creative Commons License
    Version
    experimental

    Returns the number of bit positions in self.

    Arguments

    TypeIntentOptionalAttributesName
    class(bitset_type), intent(in) :: self

    Return Value integer(kind=bits_kind)

generic, public :: clear => clear_bit, clear_range

  • private interface clear_bit_large()

    Arguments

    None
  • private interface clear_range_large()

    Arguments

    None

procedure(clear_bit_abstract), public, deferred, pass(self) :: clear_bit

  • elemental subroutine clear_bit_abstract(self, pos)Prototype

    Sets to zero the pos position in self. If pos is less than zero or greater than bits(self)-1 it is ignored.

    Read more…

    Arguments

    TypeIntentOptionalAttributesName
    class(bitset_type), intent(inout) :: self
    integer(kind=bits_kind), intent(in) :: pos

procedure(clear_range_abstract), public, deferred, pass(self) :: clear_range

  • pure subroutine clear_range_abstract(self, start_pos, stop_pos)Prototype

    Sets to zero all bits from the start_pos to stop_pos positions in set. If stop_pos < start_pos then no bits are modified. Positions outside the range 0 to bits(self)-1 are ignored.

    Arguments

    TypeIntentOptionalAttributesName
    class(bitset_type), intent(inout) :: self
    integer(kind=bits_kind), intent(in) :: start_pos
    integer(kind=bits_kind), intent(in) :: stop_pos

generic, public :: flip => flip_bit, flip_range

  • private interface flip_bit_large()

    Arguments

    None
  • private interface flip_range_large()

    Arguments

    None

procedure(flip_bit_abstract), public, deferred, pass(self) :: flip_bit

  • elemental subroutine flip_bit_abstract(self, pos)Prototype

    Flips the value at the pos position in self, provided the position is valid. If pos is less than 0 or greater than bits(self)-1, no value is changed.

    Read more…

    Arguments

    TypeIntentOptionalAttributesName
    class(bitset_type), intent(inout) :: self
    integer(kind=bits_kind), intent(in) :: pos

procedure(flip_range_abstract), public, deferred, pass(self) :: flip_range

  • pure subroutine flip_range_abstract(self, start_pos, stop_pos)Prototype

    Flips all valid bits from the start_pos to the stop_pos positions in self. If stop_pos < start_pos no bits are flipped. Positions less than 0 or greater than bits(self)-1 are ignored.

    Arguments

    TypeIntentOptionalAttributesName
    class(bitset_type), intent(inout) :: self
    integer(kind=bits_kind), intent(in) :: start_pos
    integer(kind=bits_kind), intent(in) :: stop_pos

procedure(from_string_abstract), public, deferred, pass(self) :: from_string

  • subroutine from_string_abstract(self, string, status)Prototype

    Initializes the bitset self treating string as a binary literal status may have the values: * success - if no problems were found, * alloc_fault - if allocation of the bitset failed * char_string_too_large_error - if string was too large, or * char_string_invalid_error - if string had an invalid character.

    Read more…

    Arguments

    TypeIntentOptionalAttributesName
    class(bitset_type), intent(out) :: self
    character, intent(in) :: string
    integer, intent(out), optional :: status

generic, public :: init => init_zero

  • private interface init_zero_large()

    Arguments

    None

procedure(init_zero_abstract), public, deferred, pass(self) :: init_zero

  • subroutine init_zero_abstract(self, bits, status)Prototype

    Creates the bitset, self, of size bits, with all bits initialized to zero. bits must be non-negative. If an error occurs and status is absent then processing stops with an informative stop code. status will have one of the values; * success - if no problems were found, * alloc_fault - if memory allocation failed * array_size_invalid_error - if bits is either negative or larger than 64 with self of class bitset_64, or

    Read more…

    Arguments

    TypeIntentOptionalAttributesName
    class(bitset_type), intent(out) :: self
    integer(kind=bits_kind), intent(in) :: bits
    integer, intent(out), optional :: status

procedure(input_abstract), public, deferred, pass(self) :: input

  • subroutine input_abstract(self, unit, status)Prototype

    Reads the components of the bitset, self, from the unformatted I/O unit, unit, assuming that the components were written using output. If an error occurs and status is absent then processing stops with an informative stop code. status has one of the values: * success - if no problem was found * alloc_fault - if it failed allocating memory for self, or * array_size_invalid_error if the bits(self) in unit is negative or greater than 64 for a bitset_64 input. * read_failure - if it failed during the reads from unit

    Read more…

    Arguments

    TypeIntentOptionalAttributesName
    class(bitset_type), intent(out) :: self
    integer, intent(in) :: unit
    integer, intent(out), optional :: status

procedure(none_abstract), public, deferred, pass(self) :: none

  • elemental function none_abstract(self) result(none)Prototype

    Returns .true. if none of the bits in self have the value 1.

    Read more…

    Arguments

    TypeIntentOptionalAttributesName
    class(bitset_type), intent(in) :: self

    Return Value logical

procedure(not_abstract), public, deferred, pass(self) :: not

  • elemental subroutine not_abstract(self)Prototype

    Sets the bits in self to their logical complement

    Read more…

    Arguments

    TypeIntentOptionalAttributesName
    class(bitset_type), intent(inout) :: self

procedure(output_abstract), public, deferred, pass(self) :: output

  • subroutine output_abstract(self, unit, status)Prototype

    Writes the components of the bitset, self, to the unformatted I/O unit, unit, in a unformatted sequence compatible with input. If status is absent an error results in an error stop with an informative stop code. If status is present it has the default value of success, or the value write_failure if the write failed.

    Read more…

    Arguments

    TypeIntentOptionalAttributesName
    class(bitset_type), intent(in) :: self
    integer, intent(in) :: unit
    integer, intent(out), optional :: status

generic, public :: read_bitset => read_bitset_string, read_bitset_unit

  • private interface read_bitset_string_large()

    Arguments

    None
  • private interface read_bitset_unit_large()

    Arguments

    None

procedure(read_bitset_string_abstract), public, deferred, pass(self) :: read_bitset_string

  • subroutine read_bitset_string_abstract(self, string, status)Prototype

    Uses the bitset literal in the default character string, to define the bitset, self. The literal may be preceded by an an arbitrary sequence of blank characters. If status is absent an error results in an error stop with an informative stop code. If status is present it has one of the values * success - if no problems occurred, * alloc_fault - if allocation of memory for SELF failed, * array_size_invalid_error - ifbits(self)instringis greater than 64 for abitset_64, *char_string_invalid_error- if the bitset literal has an invalid character, *char_string_too_small_error - if the string ends before all the bits are read. * integer_overflow_error - if the bitset literal has a bits(self) value too large to be represented,

    Read more…

    Arguments

    TypeIntentOptionalAttributesName
    class(bitset_type), intent(out) :: self
    character(len=*), intent(in) :: string
    integer, intent(out), optional :: status

procedure(read_bitset_unit_abstract), public, deferred, pass(self) :: read_bitset_unit

  • subroutine read_bitset_unit_abstract(self, unit, advance, status)Prototype

    Uses the bitset literal at the current position in the formatted file with I/O unit, unit, to define the bitset, self. The literal may be preceded by an an arbitrary sequence of blank characters. If advance is present it must be either 'YES' or 'NO'. If absent it has the default value of 'YES' to determine whether advancing I/O occurs. If status is absent an error results in an error stop with an informative stop code. If status is present it has one of the values: * success - if no problem occurred, * alloc_fault - if allocation of self failed, * array_size_invalid_error - if bits(self) in the bitset literal is greater than 64 for a bitset_64, * char_string_invalid_error - if the read of the bitset literal found an invalid character, * eof_failure - if a read statement reached an end-of-file before completing the read of the bitset literal, * integer_overflow_error - if the bitset literal has a bits(self) value too large to be represented, * read_failure - if a read statement fails,

    Arguments

    TypeIntentOptionalAttributesName
    class(bitset_type), intent(out) :: self
    integer, intent(in) :: unit
    character, intent(in), optional :: advance
    integer, intent(out), optional :: status

generic, public :: set => set_bit, set_range

  • private interface set_bit_large()

    Arguments

    None
  • private interface set_range_large()

    Arguments

    None

procedure(set_bit_abstract), public, deferred, pass(self) :: set_bit

  • elemental subroutine set_bit_abstract(self, pos)Prototype

    Sets the value at the pos position in self, provided the position is valid. If the position is less than 0 or greater than bits(self)-1 then self is unchanged.

    Read more…

    Arguments

    TypeIntentOptionalAttributesName
    class(bitset_type), intent(inout) :: self
    integer(kind=bits_kind), intent(in) :: pos

procedure(set_range_abstract), public, deferred, pass(self) :: set_range

  • pure subroutine set_range_abstract(self, start_pos, stop_pos)Prototype

    Sets all valid bits to 1 from the start_pos to the stop_pos positions in self. If stop_pos < start_pos no bits are changed. Positions outside the range 0 to bits(self)-1 are ignored.

    Arguments

    TypeIntentOptionalAttributesName
    class(bitset_type), intent(inout) :: self
    integer(kind=bits_kind), intent(in) :: start_pos
    integer(kind=bits_kind), intent(in) :: stop_pos

procedure(test_abstract), public, deferred, pass(self) :: test

  • elemental function test_abstract(self, pos) result(test)Prototype

    Returns .true. if the pos position is set, .false. otherwise. If pos is negative or greater than bits(self) - 1 the result is .false..

    Read more…

    Arguments

    TypeIntentOptionalAttributesName
    class(bitset_type), intent(in) :: self
    integer(kind=bits_kind), intent(in) :: pos

    Return Value logical

procedure(to_string_abstract), public, deferred, pass(self) :: to_string

  • subroutine to_string_abstract(self, string, status)Prototype

    Represents the value of self as a binary literal in string Status may have the values success or alloc_fault.

    Read more…

    Arguments

    TypeIntentOptionalAttributesName
    class(bitset_type), intent(in) :: self
    character, intent(out), allocatable:: string
    integer, intent(out), optional :: status

procedure(value_abstract), public, deferred, pass(self) :: value

  • elemental function value_abstract(self, pos) result(value)Prototype

    Returns 1 if the pos position is set, 0 otherwise. If pos is negative or greater than bits(set) - 1 the result is 0.

    Read more…

    Arguments

    TypeIntentOptionalAttributesName
    class(bitset_type), intent(in) :: self
    integer(kind=bits_kind), intent(in) :: pos

    Return Value integer

generic, public :: write_bitset => write_bitset_string, write_bitset_unit

  • private interface write_bitset_string_large()

    Arguments

    None
  • private interface write_bitset_unit_large()

    Arguments

    None

procedure(write_bitset_string_abstract), public, deferred, pass(self) :: write_bitset_string

  • subroutine write_bitset_string_abstract(self, string, status)Prototype

    Writes a bitset literal to the allocatable default character string, representing the individual bit values in the bitset_type, self. If status is absent an error results in an error stop with an informative stop code. If status is present it has the default value of success, or the value alloc_fault if allocation of the output string failed.

    Read more…

    Arguments

    TypeIntentOptionalAttributesName
    class(bitset_type), intent(in) :: self
    character(len=:), intent(out), allocatable:: string
    integer, intent(out), optional :: status

procedure(write_bitset_unit_abstract), public, deferred, pass(self) :: write_bitset_unit

  • subroutine write_bitset_unit_abstract(self, unit, advance, status)Prototype

    Writes a bitset literal to the I/O unit, unit, representing the individual bit values in the bitset_t, self. If an error occurs then processing stops with a message to error_unit. By default or if advance is present with the value 'YES', advancing output is used. If advance is present with the value 'NO', then the current record is not advanced by the write. If status is absent, an error results in an error stop with an informative stop code. If status is present it has the default value of success, the value alloc_fault if allocation of the output string failed, write_failure if the write statement outputting the literal failed.

    Arguments

    TypeIntentOptionalAttributesName
    class(bitset_type), intent(in) :: self
    integer, intent(in) :: unit
    character(len=*), intent(in), optional :: advance
    integer, intent(out), optional :: status

Source Code

    type, abstract :: bitset_type
!! version: experimental
!!
!! Parent type for bitset_64 and bitset_large ([Specification](../page/specs/stdlib_bitsets.html#the-stdlib_bitsets-derived-types))

        private
        integer(bits_kind) :: num_bits

    contains

        procedure(all_abstract), deferred, pass(self)         :: all
        procedure(any_abstract), deferred, pass(self)         :: any
        procedure(bit_count_abstract), deferred, pass(self)   :: bit_count
        procedure, pass(self)                                 :: bits
        procedure(clear_bit_abstract), deferred, pass(self)   :: clear_bit
        procedure(clear_range_abstract), deferred, pass(self) :: clear_range
        generic :: clear => clear_bit, clear_range
        procedure(flip_bit_abstract), deferred, pass(self)    :: flip_bit
        procedure(flip_range_abstract), deferred, pass(self)  :: flip_range
        generic :: flip => flip_bit, flip_range
        procedure(from_string_abstract), deferred, pass(self) :: from_string
        procedure(init_zero_abstract), deferred, pass(self)   :: init_zero
        generic :: init => init_zero
        procedure(input_abstract), deferred, pass(self)       :: input
        procedure(none_abstract), deferred, pass(self)        :: none
        procedure(not_abstract), deferred, pass(self)         :: not
        procedure(output_abstract), deferred, pass(self)      :: output
        procedure(read_bitset_string_abstract), deferred, pass(self) :: &
            read_bitset_string
        procedure(read_bitset_unit_abstract), deferred, pass(self) :: &
            read_bitset_unit
        generic :: read_bitset => read_bitset_string, read_bitset_unit
        procedure(set_bit_abstract), deferred, pass(self)     :: set_bit
        procedure(set_range_abstract), deferred, pass(self)   :: set_range
        generic :: set => set_bit, set_range
        procedure(test_abstract), deferred, pass(self)        :: test
        procedure(to_string_abstract), deferred, pass(self)   :: to_string
        procedure(value_abstract), deferred, pass(self)       :: value
        procedure(write_bitset_string_abstract), deferred, pass(self) :: &
            write_bitset_string
        procedure(write_bitset_unit_abstract), deferred, pass(self) :: &
            write_bitset_unit
        generic :: write_bitset => write_bitset_string, write_bitset_unit

    end type bitset_type