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

29
LINES

< > BotCompany Repo | #1010458 // treeSetClusters_add - add relations to a cluster list (Map<A, Collection<A>>)

JavaX fragment (include)

static <A> Collection<A> treeSetClusters_add(Map<A, Collection<A>> clusters, L<A> l) {
  for (int i = 0; i < l(l)-1; i++)
    treeSetClusters_add(clusters, l.get(i), l.get(i+1));
  ret clusters.get(first(l));
}

static <A> void treeSetClusters_add(Map<A, Collection<A>> clusters, A a, A b) {
  if (eq(a, b)) {
    Collection<A> cluster = clusters.get(a);
    if (cluster == null)
      clusters.put(a, littreeset(a));
    ret;
  }
  
  Collection<A> clusterA = clusters.get(a);
  Collection<A> clusterB = clusters.get(b);
  if (clusterA == null && clusterB == null) {
    L<A> cluster = ll(a, b);
    clusters.put(a, cluster);
    clusters.put(b, cluster);
  } else if (clusterA == null) {
    clusterB.add(a);
    clusters.put(a, clusterB);
  } else if (clusterB == null) {
    clusterA.add(b);
    clusters.put(b, clusterA);
  } else if (clusterA != clusterB)
    treeSetClusters_merge(clusters, clusterA, clusterB);
}

Author comment

Began life as a copy of #1009481

download  show line numbers  debug dex  old transpilations   

Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1010458
Snippet name: treeSetClusters_add - add relations to a cluster list (Map<A, Collection<A>>)
Eternal ID of this version: #1010458/2
Text MD5: 066db8c76b55a09f6dc3af5abaf2951c
Author: stefan
Category: javax / math
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-09-18 02:03:34
Source code size: 948 bytes / 29 lines
Pitched / IR pitched: No / No
Views / Downloads: 387 / 418
Version history: 1 change(s)
Referenced in: [show references]