mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
'v3.7.3.1'
This commit is contained in:
@@ -16,13 +16,11 @@ You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.core.brys; import gplx.*; import gplx.core.*;
|
||||
public class Bry_bfr_mkr {
|
||||
private final Bry_bfr_mkr_mgr mkr_b128 = new Bry_bfr_mkr_mgr(Tid_b128, 128);
|
||||
public Bry_bfr Get_b128() {return mkr_b128.Get();}
|
||||
public Bry_bfr Get_b512() {return mkr_b512.Get();} private final Bry_bfr_mkr_mgr mkr_b512 = new Bry_bfr_mkr_mgr(Tid_b512, 512);
|
||||
public Bry_bfr Get_k004() {return mkr_k004.Get();} private final Bry_bfr_mkr_mgr mkr_k004 = new Bry_bfr_mkr_mgr(Tid_k004, 4 * Io_mgr.Len_kb);
|
||||
public Bry_bfr Get_m001() {return mkr_m001.Get();} private final Bry_bfr_mkr_mgr mkr_m001 = new Bry_bfr_mkr_mgr(Tid_m001, 1 * Io_mgr.Len_mb);
|
||||
public void Rls(Bry_bfr v) {v.Mkr_rls();}
|
||||
public class Bry_bfr_mkr {
|
||||
public Bry_bfr Get_b128() {return mkr_b128.Get();} private final Bry_bfr_mkr_mgr mkr_b128 = new Bry_bfr_mkr_mgr(Tid_b128, 128);
|
||||
public Bry_bfr Get_b512() {return mkr_b512.Get();} private final Bry_bfr_mkr_mgr mkr_b512 = new Bry_bfr_mkr_mgr(Tid_b512, 512);
|
||||
public Bry_bfr Get_k004() {return mkr_k004.Get();} private final Bry_bfr_mkr_mgr mkr_k004 = new Bry_bfr_mkr_mgr(Tid_k004, 4 * Io_mgr.Len_kb);
|
||||
public Bry_bfr Get_m001() {return mkr_m001.Get();} private final Bry_bfr_mkr_mgr mkr_m001 = new Bry_bfr_mkr_mgr(Tid_m001, 1 * Io_mgr.Len_mb);
|
||||
public void Clear() {
|
||||
for (byte i = Tid_b128; i <= Tid_m001; i++)
|
||||
mkr(i).Clear();
|
||||
|
||||
@@ -18,15 +18,15 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.core.brys; import gplx.*; import gplx.core.*;
|
||||
public class Bry_bfr_mkr_mgr {
|
||||
private final Object thread_lock = new Object();
|
||||
private final byte mgr_id; private final int reset;
|
||||
private Bry_bfr[] used = Bry_bfr_.Ary_empty; private int used_len = 0, used_max = 0;
|
||||
private int[] free; private int free_len; private int reset;
|
||||
private int[] free; private int free_len;
|
||||
public Bry_bfr_mkr_mgr(byte mgr_id, int reset) {// NOTE: random IndexOutOfBounds errors in Get around free[--free_len] with free_len being -1; put member variable initialization within thread_lock to try to avoid; DATE:2014-09-21
|
||||
this.mgr_id = mgr_id;
|
||||
this.reset = reset;
|
||||
this.free = Int_.Ary_empty;
|
||||
this.free_len = 0;
|
||||
}
|
||||
public byte Mgr_id() {return mgr_id;} private byte mgr_id;
|
||||
public Bry_bfr Get() {
|
||||
synchronized (thread_lock) {
|
||||
Bry_bfr rv = null; int rv_idx = -1;
|
||||
@@ -62,7 +62,7 @@ public class Bry_bfr_mkr_mgr {
|
||||
for (int i = 0; i < used_max; i++) {
|
||||
Bry_bfr itm = used[i];
|
||||
if (itm != null) {
|
||||
if (!itm.Mkr_idx_is_null()) throw Err_.new_wo_type("failed to clear bfr", "idx", Int_.To_str(i));
|
||||
if (!itm.Mkr_idx_is_null()) throw Err_.new_wo_type("failed to clear bfr", "mgr_id", mgr_id, "idx", Int_.To_str(i));
|
||||
itm.Clear();
|
||||
}
|
||||
used[i] = null;
|
||||
|
||||
@@ -19,6 +19,7 @@ package gplx.core.brys; import gplx.*; import gplx.core.*;
|
||||
import gplx.core.errs.*; import gplx.core.btries.*;
|
||||
public class Bry_rdr {
|
||||
private final gplx.core.primitives.Int_obj_ref pos_ref = gplx.core.primitives.Int_obj_ref.New_neg1();
|
||||
private final Btrie_rv trv = new Btrie_rv();
|
||||
public byte[] Src() {return src;} protected byte[] src;
|
||||
public int Src_end() {return src_end;} protected int src_end;
|
||||
public int Pos() {return pos;} protected int pos;
|
||||
@@ -150,8 +151,8 @@ public class Bry_rdr {
|
||||
byte rv = Chk_or(trie, Byte_.Max_value_127);
|
||||
if (rv == Byte_.Max_value_127) err_wkr.Fail("failed trie check", "mid", String_.new_u8(Bry_.Mid_by_len_safe(src, pos, 16)));
|
||||
}
|
||||
public Object Chk_trie_as_obj(Btrie_slim_mgr trie) {
|
||||
Object rv = trie.Match_bgn(src, pos, src_end); if (rv == null) err_wkr.Fail("failed trie check", "mid", String_.new_u8(Bry_.Mid_by_len_safe(src, pos, 16)));
|
||||
public Object Chk_trie_as_obj(Btrie_rv trv, Btrie_slim_mgr trie) {
|
||||
Object rv = trie.Match_at(trv, src, pos, src_end); if (rv == null) err_wkr.Fail("failed trie check", "mid", String_.new_u8(Bry_.Mid_by_len_safe(src, pos, 16)));
|
||||
return rv;
|
||||
}
|
||||
public byte Chk_or(Btrie_slim_mgr trie, byte or) {return Chk_or(trie, pos, src_end, or);}
|
||||
@@ -161,9 +162,9 @@ public class Bry_rdr {
|
||||
return rv;
|
||||
}
|
||||
public byte Chk_or(Btrie_slim_mgr trie, int itm_bgn, int itm_end, byte or) {
|
||||
Object rv_obj = trie.Match_bgn(src, itm_bgn, itm_end);
|
||||
Object rv_obj = trie.Match_at(trv, src, itm_bgn, itm_end);
|
||||
if (rv_obj == null) return or;
|
||||
pos = trie.Match_pos();
|
||||
pos = trv.Pos();
|
||||
return ((gplx.core.primitives.Byte_obj_val)rv_obj).Val();
|
||||
}
|
||||
@gplx.Virtual public Bry_rdr Skip_ws() {
|
||||
|
||||
@@ -23,6 +23,37 @@ public class Btrie_bwd_mgr {
|
||||
Object rv = Match(src[bgn_pos], src, bgn_pos, end_pos);
|
||||
return rv == null ? null : match_pos - bgn_pos == end_pos - bgn_pos ? rv : null;
|
||||
}
|
||||
|
||||
public Object Match_at(Btrie_rv rv, byte[] src, int bgn_pos, int end_pos) {return Match_at_w_b0(rv, src[bgn_pos], src, bgn_pos, end_pos);}
|
||||
public Object Match_at_w_b0(Btrie_rv rv, byte b, byte[] src, int bgn_pos, int end_pos) {
|
||||
// NOTE: bgn, end follows same semantics as fwd where bgn >= & end < except reversed: bgn <= & end >; EX: "abcde" should pass 5, -1
|
||||
Object rv_obj = null;
|
||||
int rv_pos = bgn_pos;
|
||||
int cur_pos = bgn_pos;
|
||||
Btrie_slim_itm cur = root;
|
||||
while (true) {
|
||||
Btrie_slim_itm nxt = cur.Ary_find(b);
|
||||
if (nxt == null) { // nxt does not have b; return rv_obj;
|
||||
rv.Init(rv_pos, rv_obj);
|
||||
return rv_obj;
|
||||
}
|
||||
--cur_pos;
|
||||
if (nxt.Ary_is_empty()) { // nxt is leaf; return nxt.Val() (which should be non-null)
|
||||
rv_obj = nxt.Val();
|
||||
rv.Init(cur_pos, rv_obj);
|
||||
return rv_obj;
|
||||
}
|
||||
Object nxt_val = nxt.Val();
|
||||
if (nxt_val != null) {rv_pos = cur_pos; rv_obj = nxt_val;} // nxt is node; cache rv_obj (in case of false match)
|
||||
if (cur_pos == end_pos) { // increment cur_pos and exit if end_pos
|
||||
rv.Init(rv_pos, rv_obj);
|
||||
return rv_obj;
|
||||
}
|
||||
b = src[cur_pos];
|
||||
cur = nxt;
|
||||
}
|
||||
}
|
||||
|
||||
public Object Match_bgn(byte[] src, int bgn_pos, int end_pos) {return Match(src[bgn_pos], src, bgn_pos, end_pos);}
|
||||
public Object Match(byte b, byte[] src, int bgn_pos, int end_pos) {
|
||||
// NOTE: bgn, end follows same semantics as fwd where bgn >= & end < except reversed: bgn <= & end >; EX: "abcde" should pass 5, -1
|
||||
|
||||
@@ -22,12 +22,7 @@ public class Btrie_fast_mgr {
|
||||
public boolean CaseAny() {return root.CaseAny();} public Btrie_fast_mgr CaseAny_(boolean v) {root.CaseAny_(v); return this;}
|
||||
public int Match_pos() {return match_pos;} private int match_pos;
|
||||
|
||||
// Btrie_rv Match_at_w_b0_and_rls(byte[] src, int bgn, int end) {return Match_at_w_b0_and_rls(src[bgn], src, bgn, end);}
|
||||
// Btrie_rv Match_at_w_b0_and_rls(byte b, byte[] src, int bgn_pos, int src_end) {
|
||||
// Btrie_rv rv = ((Btrie_rv)Btrie_rv.Pool__mgr.Get_safe());
|
||||
// Match_at_w_b0(rv, b, src, bgn_pos, src_end);
|
||||
// return rv;
|
||||
// }
|
||||
public Object Match_at(Btrie_rv rv, byte[] src, int bgn_pos, int end_pos) {return Match_at_w_b0(rv, src[bgn_pos], src, bgn_pos, end_pos);}
|
||||
public Object Match_at_w_b0(Btrie_rv rv, byte b, byte[] src, int bgn_pos, int src_end) {
|
||||
Object rv_obj = null;
|
||||
int rv_pos = bgn_pos;
|
||||
|
||||
@@ -18,6 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.core.btries; import gplx.*; import gplx.core.*;
|
||||
public interface Btrie_mgr {
|
||||
int Match_pos();
|
||||
Object Match_at(Btrie_rv rv, byte[] src, int bgn_pos, int end_pos);
|
||||
Object Match_bgn(byte[] src, int bgn_pos, int end_pos);
|
||||
Btrie_mgr Add_obj(String key, Object val);
|
||||
Btrie_mgr Add_obj(byte[] key, Object val);
|
||||
|
||||
@@ -31,7 +31,7 @@ public class Btrie_slim_mgr implements Btrie_mgr {
|
||||
while (true) {
|
||||
Btrie_slim_itm nxt = cur.Ary_find(b);
|
||||
if (nxt == null) {
|
||||
rv.Init(cur_pos, rv_obj); // nxt does not hav b; return rv_obj;
|
||||
rv.Init(rv_pos, rv_obj); // nxt does not have b; return rv_obj;
|
||||
return rv_obj;
|
||||
}
|
||||
++cur_pos;
|
||||
@@ -79,6 +79,14 @@ public class Btrie_slim_mgr implements Btrie_mgr {
|
||||
Object rv_obj = Match_bgn(src, bgn, end);
|
||||
return rv_obj == null ? or : ((Byte_obj_val)rv_obj).Val();
|
||||
}
|
||||
public byte Match_byte_or(Btrie_rv trv, byte b, byte[] src, int bgn, int end, byte or) {
|
||||
Object rv_obj = Match_at_w_b0(trv, b, src, bgn, end);
|
||||
return rv_obj == null ? or : ((Byte_obj_val)rv_obj).Val();
|
||||
}
|
||||
public byte Match_byte_or(Btrie_rv trv, byte[] src, int bgn, int end, byte or) {
|
||||
Object rv_obj = Match_at(trv, src, bgn, end);
|
||||
return rv_obj == null ? or : ((Byte_obj_val)rv_obj).Val();
|
||||
}
|
||||
public Btrie_slim_mgr Add_bry_tid(byte[] bry, byte tid) {return (Btrie_slim_mgr)Add_obj(bry, Byte_obj_val.new_(tid));}
|
||||
public Btrie_slim_mgr Add_bry_int(byte[] key, int val) {return (Btrie_slim_mgr)Add_obj(key, Int_obj_val.new_(val));}
|
||||
public Btrie_slim_mgr Add_str_byte(String key, byte val) {return (Btrie_slim_mgr)Add_obj(Bry_.new_u8(key), Byte_obj_val.new_(val));}
|
||||
|
||||
@@ -24,6 +24,37 @@ public class Btrie_u8_mgr implements Btrie_mgr {
|
||||
this.root = new Btrie_u8_itm(Bry_.Empty, null);
|
||||
}
|
||||
public int Count() {return count;} private int count;
|
||||
public Object Match_at(Btrie_rv rv, byte[] src, int bgn_pos, int end_pos) {return Match_at_w_b0(rv, src[bgn_pos], src, bgn_pos, end_pos);}
|
||||
public Object Match_at_w_b0(Btrie_rv rv, byte b, byte[] src, int bgn_pos, int end_pos) {
|
||||
Object rv_obj = null;
|
||||
int rv_pos = bgn_pos;
|
||||
int cur_pos = bgn_pos;
|
||||
Btrie_u8_itm cur = root;
|
||||
while (true) {
|
||||
int c_len = Utf8_.Len_of_char_by_1st_byte(b);
|
||||
int c_end = cur_pos + c_len;
|
||||
Btrie_u8_itm nxt = cur.Nxts_find(src, cur_pos, c_end, true);
|
||||
if (nxt == null) {
|
||||
rv.Init(rv_pos, rv_obj); // nxts does not have key; return rv_obj;
|
||||
return rv_obj;
|
||||
}
|
||||
cur_pos = c_end;
|
||||
if (nxt.Nxts_is_empty()) { // nxt is leaf; return nxt.Val() (which should be non-null)
|
||||
rv_obj = nxt.Val();
|
||||
rv.Init(cur_pos, rv_obj);
|
||||
return rv_obj;
|
||||
}
|
||||
Object nxt_val = nxt.Val();
|
||||
if (nxt_val != null) {rv_pos = cur_pos; rv_obj = nxt_val;} // nxt is node; cache rv_obj (in case of false match)
|
||||
if (cur_pos == end_pos) { // increment cur_pos and exit if end
|
||||
rv.Init(rv_pos, rv_obj);
|
||||
return rv_obj;
|
||||
}
|
||||
b = src[cur_pos];
|
||||
cur = nxt;
|
||||
}
|
||||
}
|
||||
|
||||
public int Match_pos() {return match_pos;} private int match_pos;
|
||||
public Object Match_bgn(byte[] src, int bgn_pos, int end_pos) {return Match_bgn_w_byte(src[bgn_pos], src, bgn_pos, end_pos);}
|
||||
public Object Match_bgn_w_byte(byte b, byte[] src, int bgn_pos, int end_pos) {
|
||||
|
||||
35
100_core/src/gplx/core/threads/utils/Gfo_blocking_queue.java
Normal file
35
100_core/src/gplx/core/threads/utils/Gfo_blocking_queue.java
Normal file
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.core.threads.utils; import gplx.*; import gplx.core.*; import gplx.core.threads.*;
|
||||
import java.util.concurrent.ArrayBlockingQueue;
|
||||
public class Gfo_blocking_queue {
|
||||
private final ArrayBlockingQueue queue;
|
||||
public Gfo_blocking_queue(int capacity) {
|
||||
this.capacity = capacity;
|
||||
this.queue = new ArrayBlockingQueue(capacity);
|
||||
}
|
||||
public int Capacity() {return capacity;} private final int capacity;
|
||||
public void Put(Object o) {
|
||||
try {queue.put(o);}
|
||||
catch (InterruptedException e) {throw Err_.new_exc(e, "threads", "put interrupted");}
|
||||
}
|
||||
public Object Take() {
|
||||
try {return queue.take();}
|
||||
catch (InterruptedException e) {throw Err_.new_exc(e, "threads", "take interrupted");}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.core.threads.utils; import gplx.*; import gplx.core.*; import gplx.core.threads.*;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
public class Gfo_countdown_latch {
|
||||
private final CountDownLatch latch;
|
||||
public Gfo_countdown_latch(int count) {
|
||||
latch = new CountDownLatch(count);
|
||||
}
|
||||
public void Countdown() {
|
||||
latch.countDown();
|
||||
}
|
||||
public void Await() {
|
||||
try {latch.await();}
|
||||
catch (InterruptedException e) {throw Err_.new_exc(e, "threads", "await interrupted");}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user