fragment_lookup_find Function

private function fragment_lookup_find(this, monomers, n) result(idx)

Find fragment index for given monomer combination

Type Bound

fragment_lookup_t

Arguments

Type IntentOptional Attributes Name
class(fragment_lookup_t), intent(in) :: this
integer, intent(in) :: monomers(:)
integer, intent(in) :: n

Return Value integer(kind=int64)


Calls

proc~~fragment_lookup_find~~CallsGraph proc~fragment_lookup_find fragment_lookup_t%fragment_lookup_find fnv_1a_hash fnv_1a_hash proc~fragment_lookup_find->fnv_1a_hash proc~arrays_equal_internal arrays_equal_internal proc~fragment_lookup_find->proc~arrays_equal_internal sort sort proc~fragment_lookup_find->sort

Called by

proc~~fragment_lookup_find~~CalledByGraph proc~fragment_lookup_find fragment_lookup_t%fragment_lookup_find proc~compute_mbe_delta compute_mbe_delta proc~compute_mbe_delta->proc~fragment_lookup_find proc~compute_mbe_dipole compute_mbe_dipole proc~compute_mbe_dipole->proc~fragment_lookup_find proc~compute_mbe_dipole_derivatives compute_mbe_dipole_derivatives proc~compute_mbe_dipole_derivatives->proc~fragment_lookup_find proc~compute_mbe_gradient compute_mbe_gradient proc~compute_mbe_gradient->proc~fragment_lookup_find proc~compute_mbe_hessian compute_mbe_hessian proc~compute_mbe_hessian->proc~fragment_lookup_find proc~compute_mbe compute_mbe proc~compute_mbe->proc~compute_mbe_delta proc~compute_mbe->proc~compute_mbe_dipole proc~compute_mbe->proc~compute_mbe_dipole_derivatives proc~compute_mbe->proc~compute_mbe_gradient proc~compute_mbe->proc~compute_mbe_hessian proc~global_coordinator global_coordinator proc~global_coordinator->proc~compute_mbe proc~serial_fragment_processor serial_fragment_processor proc~serial_fragment_processor->proc~compute_mbe interface~global_coordinator global_coordinator interface~global_coordinator->proc~global_coordinator interface~serial_fragment_processor serial_fragment_processor interface~serial_fragment_processor->proc~serial_fragment_processor proc~mbe_run_distributed mbe_context_t%mbe_run_distributed proc~mbe_run_distributed->interface~global_coordinator proc~mbe_run_serial mbe_context_t%mbe_run_serial proc~mbe_run_serial->interface~serial_fragment_processor

Variables

Type Visibility Attributes Name Initial
integer, private :: bucket
type(hash_entry_t), private, pointer :: entry
integer(kind=int32), private :: hash_val
integer, private :: sorted_key(n)

Source Code

   function fragment_lookup_find(this, monomers, n) result(idx)
      !! Find fragment index for given monomer combination
      class(fragment_lookup_t), intent(in) :: this
      integer, intent(in) :: monomers(:), n
      integer(int64) :: idx

      integer(int32) :: hash_val
      integer :: bucket, sorted_key(n)
      type(hash_entry_t), pointer :: entry

      ! Sort monomers for canonical key
      sorted_key = monomers(1:n)
      call sort(sorted_key)

      ! Compute hash
      hash_val = fnv_1a_hash(sorted_key)
      bucket = 1 + modulo(hash_val, int(this%table_size, int32))

      ! Search chain
      if (allocated(this%table(bucket)%key)) then
         if (arrays_equal_internal(this%table(bucket)%key, sorted_key, n)) then
            idx = this%table(bucket)%value
            return
         end if
         entry => this%table(bucket)%next
         do while (associated(entry))
            if (arrays_equal_internal(entry%key, sorted_key, n)) then
               idx = entry%value
               return
            end if
            entry => entry%next
         end do
      end if

      ! Not found
      idx = -1
   end function fragment_lookup_find