When I have to write algorithms related code, I feel the limitation of my knowledge. From time to time, I need to turn to Wendy for help. She does not like to code as I do, but she completed 6 years of under-graduate and graduate study in Computer Science from Jiaotong University. I didn’t. My major was Automation, not pure computer science.
I have been puzzled by this for three days. Is there any chance that my readers can help me to solve this puzzle?
I have used query builder to create two structured query tree: q1, and q2.
I want to know whether the set represented by q1 is a subset of q2 or not.
Example in PHP:
$q1 = new AndQuery(new Query(‘id’, 123), new Query(‘age’, 13));
$q2 = new Query(‘age’, 13);
I need the function of “isSubsetOf”.
In the example, it should return true, but the real world situation is much complicated than that.
The need for such a function is, I have several search database optimized for each use, and each of them is represented by a query. For any user issued query, I can compare the query and the existing datastores. If I can confirm that the query result is subset of a datastore, I can safely use it to speed up the return of the results.