Based on the ConciseSet implementation by Alessandro Colantonio
488048
public int getLast()
  {
    if (isEmpty()) {
      return -1;
    }

    int last = 0;
    for (int i = 0; i <= lastWordIndex; i++) {
      int w = words.get(i);
      if (ConciseSetUtils.isLiteral(w)) {
        last += ConciseSetUtils.MAX_LITERAL_LENGTH;
      } else {
        last += ConciseSetUtils.maxLiteralLengthMultiplication(ConciseSetUtils.getSequenceCount(w) + 1);
      }
    }

    int w = words.get(lastWordIndex);
    if (ConciseSetUtils.isLiteral(w)) {
      last -= Integer.numberOfLeadingZeros(ConciseSetUtils.getLiteralBits(w));
    } else {
      last--;
    }
    return last;
  }
56660
private static BitSet randomBitSet(int size, int cardinality, Random random) {
        BitSet result = new BitSet(size);
        int[] chosen = new int[cardinality];

        for (int i = 0; i < cardinality; ++i) {
            chosen[i] = i;
            result.set(i);
        }
        for (int i = cardinality; i < size; ++i) {
            int j = random.nextInt(i+1);
            if (j < cardinality) {
                result.clear(chosen[j]);
                result.set(i);
                chosen[j] = i;
            }
        }
        return result;
    }
1066020
private static ImmutableSet<Symbol> lookup(
      Symbol.TypeSymbol typeSym,
      Symbol.TypeSymbol start,
      Name identifier,
      Types types,
      Symbol.PackageSymbol pkg) {
    if (typeSym == null) {
      return ImmutableSet.of();
    }

    ImmutableSet.Builder<Symbol> members = ImmutableSet.builder();

    members.addAll(lookup(types.supertype(typeSym.type).tsym, start, identifier, types, pkg));

    for (Type i : types.interfaces(typeSym.type)) {
      members.addAll(lookup(i.tsym, start, identifier, types, pkg));
    }

    OUTER:
    for (Symbol member : typeSym.members().getSymbolsByName(identifier)) {
      if (!member.isStatic()) {
        continue;
      }
      switch ((int) (member.flags() & Flags.AccessFlags)) {
        case Flags.PRIVATE:
          continue OUTER;
        case 0:
        case Flags.PROTECTED:
          if (member.packge() != pkg) {
            continue OUTER;
          }
          break;
        case Flags.PUBLIC:
        default:
          break;
      }
      if (member.isMemberOf(start, types)) {
        members.add(member);
      }
    }

    return members.build();
  }
1290336
private static <K, V> void makeSetsImmutable(Map<K, Set<V>> map) {
    Set<K> keys = map.keySet();
    for (K key : keys) {
      Set<V> value = map.get(key);
      map.put(key, Collections.unmodifiableSet(value));
    }
  }
1200753
@Override
    public NavigableSet<E> subSet(E fromElement, boolean fromInclusive, E toElement, boolean toInclusive)
    {
        int low = lowIndexOf(fromElement, fromInclusive);
        int high = highIndexOf(toElement, toInclusive);
        return new BinarySet(comparator, list.subList(low, high+1), false);
    }
899727
private DataSet<Vertex<K, VV>> createResultSimpleVertex(EdgeDirection messagingDirection,
		TypeInformation<Tuple2<K, Message>> messageTypeInfo, DataSet<LongValue> numberOfVertices) {

		DataSet<Tuple2<K, Message>> messages;

		TypeInformation<Vertex<K, VV>> vertexTypes = initialVertices.getType();

		final DeltaIteration<Vertex<K, VV>, Vertex<K, VV>> iteration =
				initialVertices.iterateDelta(initialVertices, this.maximumNumberOfIterations, 0);
				setUpIteration(iteration);

		switch (messagingDirection) {
			case IN:
				messages = buildScatterFunction(iteration, messageTypeInfo, 1, 0, numberOfVertices);
				break;
			case OUT:
				messages = buildScatterFunction(iteration, messageTypeInfo, 0, 0, numberOfVertices);
				break;
			case ALL:
				messages = buildScatterFunction(iteration, messageTypeInfo, 1, 0, numberOfVertices)
						.union(buildScatterFunction(iteration, messageTypeInfo, 0, 0, numberOfVertices));
				break;
			default:
				throw new IllegalArgumentException("Illegal edge direction");
		}

		GatherUdf<K, VV, Message> updateUdf = new GatherUdfSimpleVV<>(gatherFunction, vertexTypes);

		// build the update function (co group)
		CoGroupOperator<?, ?, Vertex<K, VV>> updates =
				messages.coGroup(iteration.getSolutionSet()).where(0).equalTo(0).with(updateUdf);

		if (this.configuration != null && this.configuration.isOptNumVertices()) {
			updates = updates.withBroadcastSet(numberOfVertices, "number of vertices");
		}

		configureUpdateFunction(updates);

		return iteration.closeWith(updates, updates);
	}
977239
function cloneSet(set, isDeep, cloneFunc) {
    var array = isDeep ? cloneFunc(setToArray(set), true) : setToArray(set);
    return arrayReduce(array, addSetEntry, new set.constructor());
  }
1271330
private Vec[][] makeTemplates(Frame dataset, double[] ratios) {
    Vec anyVec = dataset.anyVec();
    final long[][] espcPerSplit = computeEspcPerSplit(anyVec.espc(), anyVec.length(), ratios);
    final int num = dataset.numCols(); // number of columns in input frame
    final int nsplits = espcPerSplit.length; // number of splits
    final String[][] domains = dataset.domains(); // domains
    final byte[] types = new byte[num];
    int j=0;
    for (Vec v : dataset.vecs()) types[j++] = v.get_type();

    Vec[][] t = new Vec[nsplits][/*num*/]; // resulting vectors for all
    for (int i=0; i<nsplits; i++) {
      // vectors for j-th split
      Key vkey = Vec.newKey();
      int rowLayout = Vec.ESPC.rowLayout(vkey,espcPerSplit[i]);
      t[i] = new Vec(vkey,rowLayout).makeCons(num, 0, domains, types);
    }
    return t;
  }
435820
function tightTree(t, g) {
  function dfs(v) {
    _.forEach(g.nodeEdges(v), function(e) {
      var edgeV = e.v,
        w = (v === edgeV) ? e.w : edgeV;
      if (!t.hasNode(w) && !slack(g, e)) {
        t.setNode(w, {});
        t.setEdge(v, w, {});
        dfs(w);
      }
    });
  }

  _.forEach(t.nodes(), dfs);
  return t.nodeCount();
}
10272
private static ImmutableSet<RelationID> attributeOccurrencesUnion(QuotedID id,
                                                                      RAExpressionAttributes re1,
                                                                      RAExpressionAttributes re2) {

        ImmutableSet<RelationID> s1 = re1.attributeOccurrences.get(id);
        ImmutableSet<RelationID> s2 = re2.attributeOccurrences.get(id);

        if (s1 == null)
            return s2;

        if (s2 == null)
            return s1;

        return ImmutableSet.<RelationID>builder().addAll(s1).addAll(s2).build();
    }
1280609
def coupling(corpus_or_featureset, featureset_name=None,
             min_weight=1, filter=lambda f, v, c, dc: True,
             node_attrs=[]):
    

    featureset = _get_featureset(corpus_or_featureset, featureset_name)

    c = lambda f: featureset.count(f)           # Overall count.
    dc = lambda f: featureset.documentCount(f)  # Document count.
    f = lambda elem: featureset.index[elem]
    v = lambda p, f: featureset.features[p].value(f)

    select = lambda p, elem: filter(f(elem), v(p, f(elem)), c(f(elem)), dc(f(elem)))

    pairs = defaultdict(list)
    for elem, papers in featureset.with_feature.iteritems():
        selected = [p for p in papers if select(p, elem)]
        for combo in combinations(selected, 2):
            combo = tuple(sorted(combo))
            pairs[combo].append(featureset.index[elem])

    graph = nx.Graph()
    for combo, features in pairs.iteritems():
        count = len(features)
        if count >= min_weight:
            graph.add_edge(combo[0], combo[1], features=features, weight=count)

    # Add node attributes.
    for attr in node_attrs:
        for node in graph.nodes():
            value = ''
            if node in corpus_or_featureset:
                paper = corpus_or_featureset[node]
                if hasattr(paper, attr):
                    value = getattr(paper, attr)
                    if value is None:
                        value = ''
                    elif callable(value):
                        value = value()
            graph.node[node][attr] = value

    return graph
847939
private int reduceNondominatedSet(double[][] front, int noPoints, int objective,
                                    double threshold) {
    int n;
    int i;

    n = noPoints;
    for (i = 0; i < n; i++) {
      if (front[i][objective] <= threshold) {
        n--;
        swap(front, i, n);
      }
    }

    return n;
  }
1118070
def coord_list_mapping(subset, superset, atol=1e-8):
    
    c1 = np.array(subset)
    c2 = np.array(superset)
    inds = np.where(np.all(np.isclose(c1[:, None, :], c2[None, :, :], atol=atol),
                           axis=2))[1]
    result = c2[inds]
    if not np.allclose(c1, result, atol=atol):
        if not is_coord_subset(subset, superset):
            raise ValueError("subset is not a subset of superset")
    if not result.shape == c1.shape:
        raise ValueError("Something wrong with the inputs, likely duplicates "
                         "in superset")
    return inds
278076
function bnpDAddOffset(n,w) {
  while(this.t <= w) this[this.t++] = 0;
  this[w] += n;
  while(this[w] >= this.DV) {
    this[w] -= this.DV;
    if(++w >= this.t) this[this.t++] = 0;
    ++this[w];
  }
}
160693
def MultiSet(self,
               subject,
               values,
               timestamp=None,
               replace=True,
               sync=True,
               to_delete=None):
    """"""
    to_delete = set(to_delete or [])

    # Prepare a bulk insert operation.
    subject = utils.SmartUnicode(subject)
    to_insert = []
    to_replace = []
    transaction = []

    # Build a document for each unique timestamp.
    for attribute, sequence in iteritems(values):
      for value in sequence:
        if isinstance(value, tuple):
          value, entry_timestamp = value
        else:
          entry_timestamp = timestamp

        if entry_timestamp is None:
          entry_timestamp = timestamp

        if entry_timestamp is not None:
          entry_timestamp = int(entry_timestamp)
        else:
          entry_timestamp = time.time() * 1e6

        attribute = utils.SmartUnicode(attribute)
        data = self._Encode(value)

        # Replacing means to delete all versions of the attribute first.
        if replace or attribute in to_delete:
          existing = self._CountExistingRows(subject, attribute)
          if existing:
            to_replace.append([subject, attribute, data, entry_timestamp])
          else:
            to_insert.append([subject, attribute, data, entry_timestamp])
          if attribute in to_delete:
            to_delete.remove(attribute)

        else:
          to_insert.append([subject, attribute, data, entry_timestamp])

    if to_delete:
      self.DeleteAttributes(subject, to_delete)

    if sync:
      if to_replace:
        transaction.extend(self._BuildReplaces(to_replace))
      if to_insert:
        transaction.extend(self._BuildInserts(to_insert))
      if transaction:
        self._ExecuteTransaction(transaction)
    else:
      if to_replace:
        with self.buffer_lock:
          self.to_replace.extend(to_replace)
      if to_insert:
        with self.buffer_lock:
          self.to_insert.extend(to_insert)
1166188
def meet(self, featuresets):
        """"""
        concepts = (f.concept for f in featuresets)
        meet = self.lattice.meet(concepts)
        return self._featuresets[meet.index]
1172017
function(set) {
            var l = set.length;
            for(var i=0; i<l; i++) if(!__.isLinear(set[i])) return false;
            return true;
        }