fragment_lookup_insert Subroutine

private subroutine fragment_lookup_insert(this, monomers, n, fragment_idx, error)

Insert a monomer combination -> fragment index mapping

Type Bound

fragment_lookup_t

Arguments

Type IntentOptional Attributes Name
class(fragment_lookup_t), intent(inout) :: this
integer, intent(in) :: monomers(:)
integer, intent(in) :: n
integer(kind=int64), intent(in) :: fragment_idx
type(error_t), intent(out), optional :: error

Calls

proc~~fragment_lookup_insert~~CallsGraph proc~fragment_lookup_insert fragment_lookup_t%fragment_lookup_insert fnv_1a_hash fnv_1a_hash proc~fragment_lookup_insert->fnv_1a_hash proc~error_set error_t%error_set proc~fragment_lookup_insert->proc~error_set sort sort proc~fragment_lookup_insert->sort

Called by

proc~~fragment_lookup_insert~~CalledByGraph proc~fragment_lookup_insert fragment_lookup_t%fragment_lookup_insert proc~build_mbe_lookup_table build_mbe_lookup_table proc~build_mbe_lookup_table->proc~fragment_lookup_insert proc~compute_mbe compute_mbe proc~compute_mbe->proc~build_mbe_lookup_table 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
integer(kind=int32), private :: hash_val
type(hash_entry_t), private, pointer :: new_entry
integer, private, allocatable :: sorted_key(:)

Source Code

   subroutine fragment_lookup_insert(this, monomers, n, fragment_idx, error)
      !! Insert a monomer combination -> fragment index mapping
      class(fragment_lookup_t), intent(inout) :: this
      integer, intent(in) :: monomers(:), n
      integer(int64), intent(in) :: fragment_idx
      type(error_t), intent(out), optional :: error

      integer(int32) :: hash_val
      integer :: bucket
      type(hash_entry_t), pointer :: new_entry
      integer, allocatable :: sorted_key(:)

      if (.not. this%initialized) then
         if (present(error)) then
            call error%set(ERROR_VALIDATION, "Hash table not initialized")
         end if
         return
      end if

      ! Sort monomers for canonical key
      allocate (sorted_key(n))
      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))

      ! Check if this is the first entry in bucket
      if (.not. allocated(this%table(bucket)%key)) then
         ! First entry in this bucket - use the head entry
         allocate (this%table(bucket)%key(n))
         this%table(bucket)%key = sorted_key
         this%table(bucket)%value = fragment_idx
         this%n_entries = this%n_entries + 1
      else
         ! Bucket already has entries - chain new entry
         allocate (new_entry)
         allocate (new_entry%key(n))
         new_entry%key = sorted_key
         new_entry%value = fragment_idx
         new_entry%next => this%table(bucket)%next
         this%table(bucket)%next => new_entry
         this%n_entries = this%n_entries + 1
      end if

      deallocate (sorted_key)
   end subroutine fragment_lookup_insert