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).

!7

cmodule RegexpMatcher > DynPrintLogAndEnabled {
  switchable bool verbose;
  
  transient L<Job> jobs = syncLinkedList();
  transient ReliableSingleThread rst = dm_rst_inInit(this, r step);
  
  // stats
  transient long jobsDone;
  transient Job shortestRegexp, longestRegexp;
  transient Job quickestJob, slowestJob;

  sclass Job {
    S regexp, input;
    bool ignoreCase;
    O whenDone; // voidfunc(Matcher, bool). called with null if error
    S moduleID; // for who are we doing this
    long executionTime; // after it ran
    
    void clean { whenDone = null; }
  }
  
  void step {
    Job job;
    while (licensed() && (job = syncPopFirst(jobs)) != null) pcall {
      doJob(job);
      job.clean();
      
      // update stats & print
      
      ++jobsDone;
      if (verbose) print("Regexp matching done in " + job.executionTime + " ms");
      shortestRegexp = switchIfShorterInField regexp(job, shortestRegexp,
        r { if (verbose) print("New shortest regexp!") });
      longestRegexp = switchIfLongerInField regexp(job, longestRegexp,
        r { if (verbose) print("New longest regexp!") });
      if (quickestJob == null || job.executionTime < quickestJob.executionTime) {
        quickestJob = job;
        if (verbose) print("New quickest job!");
      }
      if (slowestJob == null || job.executionTime > slowestJob.executionTime) {
        slowestJob = job;
        if (verbose) print("New slowest job!");
      }
    }
  }
  
  void doJob(Job j) {
    if (!dm_moduleExists(j.moduleID)) ret;
    long time = sysNow();
    Matcher m = null;
    bool found = false;
    pcall {
      m = safeRegexpPossiblyIC(j.ignoreCase, j.regexp, j.input);
      found = m.find();
    }
    j.executionTime = elapsedMS(time);
    callF(j.whenDone, m, found);
  }
  
  // API
  
  void addJob(S moduleID, S regexp, S input, bool ignoreCase, O whenDone) q {
    jobs.add(nu Job(+moduleID, +regexp, +input, +ignoreCase, +whenDone));
 // change();
    rst.trigger();
  }
  
  void deleteJobsForModule(S moduleID) q {
    syncFilterLinkedListInPlace(jobs, job -> eq(job.moduleID, moduleID));
 // change();
  }
}

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: 191 / 1260
Version history: 21 change(s)
Referenced in: [show references]