more efficient find_gaps function using Rcpp