我有一份样本ID列表,每个样本都拥有[x]=2, [y]=3, [z]= 4
格式的某些信息。我想写一个函数,它返回满足某些条件的样本ID列表。
我的查询结构是[cond1,cond2,...,condn, operator=AND/OR]
。例如,如果我的查询是:[x<5,y==3,x!=2,operator=AND]
,那么以下是我的算法来处理它,
Step 1: Allocate (malloc) 2 array pointers namely arr_final, arr_temp.
Step 2: Find all the samples with `x<5` store them in array `arr_final`,
Step 3: Find all the samples with `y==3`, store them in array `arr_temp`.
Step 4: Find the intersection of arr_final, arr_temp and store the result in `arr_final`.
Step 5: Find all the samples with `x!=2` store them in array `arr_temp`.
Step 6: Repeat step 4
Step 7: Return arr_final
如果运算符为OR
,那么我只保留一个arr_final
数组,如果它们不在数组中,则存储样本ID并返回arr_final
at结束。
上述算法最佳工作还是更好?