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

72
LINES

< > BotCompany Repo | #1023993 // Regexp Matcher - module dedicated to matching regexps for other modules [dev.]

JavaX source code (Dynamic Module) [tags: use-pretranspiled] - run with: Stefan's OS

Uses 911K of libraries. Click here for Pure Java version (4788L/25K).

1  
!7
2  
3  
cmodule RegexpMatcher > DynPrintLogAndEnabled {
4  
  switchable bool verbose;
5  
  
6  
  transient L<Job> jobs = syncLinkedList();
7  
  transient ReliableSingleThread rst = dm_rst_inInit(this, r step);
8  
  
9  
  // stats
10  
  transient long jobsDone;
11  
  transient Job shortestRegexp, longestRegexp;
12  
  transient Job quickestJob, slowestJob;
13  
14  
  sclass Job {
15  
    S regexp, input;
16  
    bool ignoreCase;
17  
    O whenDone; // voidfunc(Matcher, bool). called with null if error
18  
    S moduleID; // for who are we doing this
19  
    long executionTime; // after it ran
20  
    
21  
    void clean { whenDone = null; }
22  
  }
23  
  
24  
  void step {
25  
    Job job;
26  
    while (licensed() && (job = syncPopFirst(jobs)) != null) pcall {
27  
      doJob(job);
28  
      job.clean();
29  
      
30  
      // update stats & print
31  
      
32  
      ++jobsDone;
33  
      if (verbose) print("Regexp matching done in " + job.executionTime + " ms");
34  
      shortestRegexp = switchIfShorterInField regexp(job, shortestRegexp,
35  
        r { if (verbose) print("New shortest regexp!") });
36  
      longestRegexp = switchIfLongerInField regexp(job, longestRegexp,
37  
        r { if (verbose) print("New longest regexp!") });
38  
      if (quickestJob == null || job.executionTime < quickestJob.executionTime) {
39  
        quickestJob = job;
40  
        if (verbose) print("New quickest job!");
41  
      }
42  
      if (slowestJob == null || job.executionTime > slowestJob.executionTime) {
43  
        slowestJob = job;
44  
        if (verbose) print("New slowest job!");
45  
      }
46  
    }
47  
  }
48  
  
49  
  void doJob(Job j) {
50  
    if (!dm_moduleExists(j.moduleID)) ret;
51  
    long time = sysNow();
52  
    Matcher m = null;
53  
    bool found = false;
54  
    pcall {
55  
      m = safeRegexpPossiblyIC(j.ignoreCase, j.regexp, j.input);
56  
      found = m.find();
57  
    }
58  
    j.executionTime = elapsedMS(time);
59  
    callF(j.whenDone, m, found);
60  
  }
61  
  
62  
  // API
63  
  
64  
  void addJob(S moduleID, S regexp, S input, bool ignoreCase, O whenDone) q {
65  
    jobs.add(nu Job(+moduleID, +regexp, +input, +ignoreCase, +whenDone));
 // change();
66  
    rst.trigger();
67  
  }
68  
  
69  
  void deleteJobsForModule(S moduleID) q {
70  
    syncFilterLinkedListInPlace(jobs, job -> eq(job.moduleID, moduleID));
 // change();
71  
  }
72  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 6 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1023993
Snippet name: Regexp Matcher - module dedicated to matching regexps for other modules [dev.]
Eternal ID of this version: #1023993/22
Text MD5: 21edd9b2d465fa5f070c8aa7a9402edb
Transpilation MD5: c4934e7bc2177d57df7aab5ee3fc246c
Author: stefan
Category: javax / modules
Type: JavaX source code (Dynamic Module)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-07-16 00:51:55
Source code size: 2189 bytes / 72 lines
Pitched / IR pitched: No / No
Views / Downloads: 194 / 1265
Version history: 21 change(s)
Referenced in: [show references]