Insert a monomer combination -> fragment index mapping
| Type | Intent | Optional | 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 |
| 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(:) |
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