subroutine add_guga_lists(nDets1, nDets2, list1, list2)
integer, intent(inout) :: nDets1
integer, intent(in) :: nDets2
integer(n_int), intent(inout) :: list1(0:, 1:), list2(0:, 1:)
integer :: i, min_ind, pos, abs_pos, j
HElement_t(dp) :: tmp_mat
! first sort lists to use binary search
call sort(list1(:, 1:nDets1), ilut_lt, ilut_gt)
call sort(list2(:, 1:nDets2), ilut_lt, ilut_gt)
abs_pos = 0
min_ind = 1
do i = 1, nDets2
pos = binary_search_ilut(list1(0:nifd, min_ind:ndets1), list2(0:nifd, i))
if (pos > 0) then
! try new implementation of that without the need of an extra
! output list
! need the absolute position after binary searches in only
! sublists
abs_pos = abs_pos + pos
! when element found just update the matrix element and update
! the indices
tmp_mat = extract_h_element(list1(:, abs_pos)) + &
extract_h_element(list2(:, i))
call encode_matrix_element(list1(:, abs_pos), tmp_mat, 1)
! min_ind to search next element is then
min_ind = min_ind + pos
else
! if the entry is not in list1 i have to move down all
! subsequent elements after the found position and insert the
! new entry at the indicated absolute position
abs_pos = abs_pos - pos
! is this too big to copy in one go??
do j = nDets1, abs_pos, -1
list1(:, j + 1) = list1(:, j)
end do
! and add the new entry
list1(:, abs_pos) = list2(:, i)
! the minimum index to search from now on should not include
! the inserted element, since there should be no repetitions
! in both lists
min_ind = min_ind - pos
! and i have to update the number of determinants in list1
nDets1 = nDets1 + 1
end if
end do
end subroutine add_guga_lists