Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

46
LINES

< > BotCompany Repo | #1023276 // findConceptWhereCI - new optimized version

JavaX fragment (include) [tags: use-pretranspiled]

Transpiled version (15053L) is out of date.

1  
static <A extends Concept> A nuLike findConceptWhereCI(Class<A> c, O... params) {
2  
  ret findConceptWhereCI(db_mainConcepts(), c, params);
3  
}
4  
5  
static <A extends Concept> A findConceptWhereCI(Concepts concepts, Class<A> c, O... params) {
6  
  params = expandParams(c, params);
7  
  
8  
  // find smallest index to use
9  
  new Lowest<IF0<Cl<A>>> bestIndex;
10  
  
11  
  if (concepts.ciFieldIndices != null)
12  
    for ping (int i = 0; i < l(params); i += 2) {
13  
      O val = params[i+1];
14  
      IFieldIndex<A, O> index = concepts.getCIFieldIndex(c, (S) params[i]);
15  
      if (index != null) {
16  
        Cl<A> l = index.getAll(val);
17  
        bestIndex.put(() -> l, l(l));
18  
      }
19  
      if (concepts.useBackRefsForSearches && val instanceof Concept) {
20  
        // conservatively use full ref count as score until we store backRefs by class
21  
        bestIndex.put(() -> findBackRefs(val/Concept, c), val/Concept._backRefCount());
22  
      }
23  
    }
24  
  
25  
  ifdef findConceptWhereCI_debug
26  
    print("findConceptWhereCI bestIndex count=" + bestIndex.score());
27  
  endifdef
28  
  if (bestIndex.has()) {
29  
    Cl<A> l = bestIndex!!;
30  
    if (l(params) == 2) ret first(l); // nothing to filter, index should suffice
31  
    for ping (A x : l)
32  
      if (checkConceptFieldsIC(x, params)) ret x;
33  
    null;
34  
  } else {
35  
    // table scan
36  
    for ping (A x : concepts.list(c))
37  
      if (checkConceptFieldsIC(x, params)) ret x;
38  
    null;
39  
  }
40  
}
41  
42  
static Concept findConceptWhereCI(Concepts concepts, S c, O... params) {
43  
  for ping (Concept x : concepts.list(c))
44  
    if (checkConceptFieldsIC(x, params)) ret x;
45  
  null;
46  
}

Author comment

Began life as a copy of #1005039

download  show line numbers  debug dex  old transpilations   

Travelled to 8 computer(s): bhatertpkbcr, cfunsshuasjs, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, qsqiayxyrbia, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1023276
Snippet name: findConceptWhereCI - new optimized version
Eternal ID of this version: #1023276/9
Text MD5: 2034d857522b18c47d2b008736686fcd
Author: stefan
Category: javax / concepts
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-04-29 12:27:42
Source code size: 1593 bytes / 46 lines
Pitched / IR pitched: No / No
Views / Downloads: 331 / 467
Version history: 8 change(s)
Referenced in: [show references]