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

32
LINES

< > BotCompany Repo | #1032781 // ipToCountry_old - keeps data in memory (version with new database), returns ISO codes

JavaX fragment (include)

sS ipToCountry_dataSnippet = #1008743;

static NavigableMap<Long, S> ipToCountry_data = new TreeMap; //synchroNavigableTreeMap();
static Lock ipToCountry_lock = lock();

static S ipToCountry_old(S ip) null on exception {
  long ipNum = ipToInt(trim(ip));
  lock ipToCountry_lock;
  ipToCountry_init();
  Long key = ipToCountry_data.floorKey(ipNum);
  ret key == null ? null : ipToCountry_data.get(key);
}

static void ipToCountry_init() {
  lock ipToCountry_lock;
  if (nempty(ipToCountry_data)) ret;
    
  long start = 0;
  for (S s : linesFromReader(utf8bufferedReader(gzInputStream(loadLibrary(ipToCountry_dataSnippet))))) {
    L<S> l = splitAtSpace(s);
    if (l(l) < 2) continue;
    long diff = parseLong(first(l));
    S country = intern(last(l));
    start += diff;
    ipToCountry_data.put(start, country);
  }
}

static void ipToCountry_clearCache() {
  lock ipToCountry_lock;
  ipToCountry_data.clear();
}

Author comment

Began life as a copy of #1008738

download  show line numbers  debug dex  old transpilations   

Travelled to 3 computer(s): bhatertpkbcr, mowyntqkapby, mqqgnosmbjvj

No comments. add comment

-
Snippet ID: #1032781
Snippet name: ipToCountry_old - keeps data in memory (version with new database), returns ISO codes
Eternal ID of this version: #1032781/3
Text MD5: ffa09cb0f42de2beefb36c1296ae99a5
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-10-06 04:00:32
Source code size: 949 bytes / 32 lines
Pitched / IR pitched: No / No
Views / Downloads: 133 / 148
Version history: 2 change(s)
Referenced in: