[...]
> I'm not completly sure about that, but the documentation > of Search / Find / Select using multiProperty keys is rare, > so i'd like to make sure i understand what you intended. > > BTW. can you say somewhere in the documentation some more words about > the difference between Find and Search, > one of them is simply a loop , the other one is a binary search, but > which is what , the documentation is a bit unclear ( for me ).
Yes, these are ill-defined, and part of the problem is that the Compare I use internally is tricky. The logic is as follows:
- Select compares on the properties present in the key arg(s) - Find also compares only on the properties specified in the key - Search compares on the view's native order (i.e. from GetAs)
If you have a view V with properties A, B, C, and search on (A,E,C), then it will compare on A first, then compare on B with its default value, then compare on C, and ignore E.
This is not as restrictive as it seems, because you can use Sort, then Project to reorder keys (though Sort takes time to set up, clearly).
I am adding a new member to c4_View, called Locate:
int c4_View::Locate(const c4_RowRef& crit_, int* pos_) const;
It returns the number of matching items, and optionally the position of the first one in the pos_ argument. The code is below, in case you want to add it to your code right now. [...]
-jcw
int c4_View::Locate(const c4_RowRef& crit_, int* pos_) const { d4_assertThis; d4_assert(_seq != 0); int l = -1, u = GetSize(); while (l + 1 != u) { const int m = (l + u) >> 1; if (_seq->Compare(m, &crit_) < 0) l = m; else u = m; } int l2 = -1, u2 = GetSize(); while (l2 + 1 != u2) { const int m = (l2 + u2) >> 1; if (_seq->Compare(m, &crit_) <= 0) l2 = m; else u2 = m; } if (pos_ != 0) *pos_ = u; return u2 - u; }