myuniq <- function(df){
  if(NROW(df)<2){
    return(df)
  } else {
    uniq=!apply(apply(df,2,"%in%",df[1,]),1,any)
    return(rbind(df[1,],myuniq(df[uniq,])))
  }
}

another_unique <- function(df){
  if(nrow(df)<2){
    return(df)
  } 
  
  list_x = c(df$x)
  list_y = c(df$y)
  list_all = c()
  list_x_new = c()
  list_y_new = c()
  for(x in 1:length(list_x)){
    if(list_x[x] %in% list_all | list_y[x] %in% list_all){
      
    }else{
      list_all = c(list_all, list_x[x], list_y[x])
      list_x_new = c(list_x_new, list_x[x])
      list_y_new = c(list_y_new, list_y[x])
    }
  }
  return(data.frame(x=list_x_new, y=list_y_new))

}

set.seed(123456)
n=10000
df=data.frame(x=sample(1:500,n,replace = T)
              ,y=sample(1:500,n,replace = T))


# 測測看
ss <- Sys.time()
new_df_a <- another_unique(df)
print(paste('another_unique:', Sys.time() - ss))
summary(new_df_a)

# showfeb大範例
ss <- Sys.time()
new_df <- myuniq(df)
print(paste('myuniq:', Sys.time() - ss))
summary(new_df)

print(sum(new_df_a == new_df) / 2 == nrow(new_df))
