static O analyzeBitMap_idToText; // func(long) -> S // Looks only at the values static void analyzeBitMap(MultiMap<Long, Long> bitMap) { analyzeBitMap(values(bitMap.data)); } static void analyzeBitMap(Collection<L<Long>> bitMap) { if (bitMap.isEmpty()) ret; new HashSet<Long> allSeen; for (L<Long> l : bitMap) allSeen.addAll(l); printStruct(+allSeen); MultiMap<Long, Long> implies = fullSelfMap(allSeen); MultiMap<Long, Long> eq = fullSelfMap(allSeen); for (L<Long> l : bitMap) { HashSet<Long> set = new HashSet(l); for (Long a : cloneList(implies.keySet())) { bool ax = set.contains(a); for (Long b : cloneList(implies.get(a))) { bool bx = set.contains(b); if (ax && !bx) implies.remove(a, b); } } for (Long a : cloneList(eq.keySet())) { bool ax = set.contains(a); for (Long b : cloneList(eq.get(a))) { bool bx = set.contains(b); if (ax != bx) eq.remove(a, b); } } } printStruct(+implies); //printStruct(+eq); L<L<Long>> clusters = multiMapToClusters(eq); for i over clusters: print("Cluster \* i+1 */: " + struct(mapIfFunctionNotNull(analyzeBitMap_idToText, clusters.get(i)))); } static MultiMap<Long, Long> fullSelfMap(Collection<Long> l) { new MultiMap<Long, Long> mm; for (Long x : l) mm.putAll(x, l); ret mm; } static L<L<Long>> multiMapToClusters(MultiMap<Long, Long> mm) { // a cluster is a list of concepts. // first, make trivial clusters (one per item). Map<Long, L<Long>> clusters = new TreeMap<Long, L<Long>>(); for (Long a : mm.keySet()) { if (!clusters.containsKey(a)) clusters.put(a, ll(a)); } // then, merge the clusters. for (Long a : mm.keySet()) for (Long b : mm.get(a)) { L<Long> c1 = clusters.get(a); L<Long> c2 = clusters.get(b); if (c1 != c2) // different clusters, need to merge! mergeClusters(clusters, c1, c2); } ret asList(new HashSet<L<Long>>(clusters.values())); } static void mergeClusters(Map<Long, L<Long>> clusters, L<Long> c1, L<Long> c2) { for (Long x : c2) { clusters.put(x, c1); c1.add(x); } }
download show line numbers debug dex old transpilations
Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, ddnzoavkxhuk, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1005534 |
Snippet name: | analyzeBitMap |
Eternal ID of this version: | #1005534/1 |
Text MD5: | a41a73c41a52102f55e6478537f2e7b0 |
Author: | stefan |
Category: | javax / logic |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2016-11-27 14:04:39 |
Source code size: | 2265 bytes / 81 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 513 / 736 |
Referenced in: | [show references] |