Return contiguous parts of collection as separate collections.

        Return as list of :py:class:`~clique.collection.Collection` instances.
973404
def separate(self):
        '''

        '''
        collections = []
        start = None
        end = None

        for index in self.indexes:
            if start is None:
                start = index
                end = start
                continue

            if index != (end + 1):
                collections.append(
                    Collection(self.head, self.tail, self.padding,
                               indexes=set(range(start, end + 1)))
                )
                start = index

            end = index

        if start is None:
            collections.append(
                Collection(self.head, self.tail, self.padding)
            )
        else:
            collections.append(
                Collection(self.head, self.tail, self.padding,
                           indexes=range(start, end + 1))
            )

        return collections
198115
def get_collection(source, name, collection_format, default):
    
    if collection_format in COLLECTION_SEP:
        separator = COLLECTION_SEP[collection_format]
        value = source.get(name, None)
        if value is None:
            return default
        return value.split(separator)
    if collection_format == 'brackets':
        return source.getall(name + '[]', default)
    else:                       # format: multi
        return source.getall(name, default)
96714
def inner(self):
        
        self.get_collections_data()

        inner_join = self.merge_join_docs(set(self.collections_data['left'].keys()) & set(
            self.collections_data['right'].keys()))

        return inner_join
1073219
def get_collections(module_ident, plpy):
    """"""
    # Make sure to only return one match per collection and only if it is the
    # latest collection (which may not be the same as what is in
    # latest_modules)
    plan = plpy.prepare('''
WITH RECURSIVE t(node, parent, path, document) AS (
        SELECT tr.nodeid, tr.parent_id, ARRAY[tr.nodeid], tr.documentid
        FROM trees tr
        WHERE tr.documentid = $1 and tr.is_collated = 'False'
    UNION ALL
        SELECT c.nodeid, c.parent_id, path || ARRAY[c.nodeid], c.documentid
        FROM trees c JOIN t ON (c.nodeid = t.parent)
        WHERE not c.nodeid = ANY(t.path)
    ),
    latest(module_ident) AS (
    SELECT module_ident FROM (
        SELECT m.module_ident, m.revised,
            MAX(m.revised) OVER (PARTITION BY m.uuid) as latest
        FROM  modules m where m.portal_type = 'Collection'
    ) r
    WHERE r.revised = r.latest
    )
    SELECT module_ident FROM t, latest
        WHERE latest.module_ident = t.document
    ''', ('integer',))
    for i in plpy.execute(plan, (module_ident,)):
        yield i['module_ident']
914444
def collection(cls, cid):
        
        url = urljoin(config.API_URL, 'collections/%s' % cid)
        return Collection(cls.query(url=url))
409413
def k_partitions(collection, k):
    
    collection = list(collection)
    n = len(collection)

    # Special cases
    if n == 0 or k < 1:
        return []
    if k == 1:
        return [[collection]]

    a = [0] * (n + 1)
    for j in range(1, k + 1):
        a[n - k + j] = j - 1
    return _f(k, n, 0, n, a, k, collection)
699720
def distinct(self, numPartitions=None):
        
        return self.map(lambda x: (x, None)) \
                   .reduceByKey(lambda x, _: x, numPartitions) \
                   .map(lambda x: x[0])
736769
def is_periodically_contiguous( self ):
        
        edges = self.sites_at_edges()
        is_contiguous = [ False, False, False ]
        along_x = any( [ s2 in s1.p_neighbours for s1 in edges[0] for s2 in edges[1] ] )
        along_y = any( [ s2 in s1.p_neighbours for s1 in edges[2] for s2 in edges[3] ] )
        along_z = any( [ s2 in s1.p_neighbours for s1 in edges[4] for s2 in edges[5] ] )
        return ( along_x, along_y, along_z )
170826
def visit_Slice(self, node):
        
        self.generic_visit(node)
        if node.step is None or (isinstance(node.step, ast.Num) and
                                 node.step.n == 1):
            self.result[node] = self.builder.NamedType(
                'pythonic::types::contiguous_slice')
        else:
            self.result[node] = self.builder.NamedType(
                'pythonic::types::slice')
935826
def find(cls, *args, **kwargs):
        
        return list(cls.collection.find(*args, **kwargs))
545222
public static <T> List<T> getUnique(Collection<T> collection) {
        HashSet<T> set = new HashSet<>();
        List<T> out = new ArrayList<>();
        for (T t : collection) {
            if (!set.contains(t)) {
                out.add(t);
                set.add(t);
            }
        }
        return out;
    }
114301
def _subset(self, subset):
        """"""
        pl = Pipeline(bundle=self.bundle)
        for group_name, pl_segment in iteritems(self):
            if group_name not in subset:
                continue
            pl[group_name] = pl_segment
        return pl
616362
def collection_keys(coll, sep='.'):
    
    def _keys(x, pre=''):
        for k in x:
            yield (pre + k)
            if isinstance(x[k], dict):
                for nested in _keys(x[k], pre + k + sep):
                    yield nested

    return list(_keys(coll.find_one()))
400397
def all(self):
        
        return self._client.get(
            url=self._client.get_full_url(
                self.get_path('collection', realm=self._realm_name)
            )
        )
1013102
def _ConstructPartitions(self, collection_links, partitions_per_node):
        
        collections_node_count = len(collection_links)
        partitions = [partition._Partition() for _ in xrange(0, partitions_per_node * collections_node_count)]

        index = 0
        for collection_node in collection_links:
            hash_value = self.hash_generator.ComputeHash(self._GetBytes(collection_node))
            for _ in xrange(0, partitions_per_node):
                partitions[index] = partition._Partition(hash_value, collection_node)
                index += 1
                hash_value = self.hash_generator.ComputeHash(hash_value)

        partitions.sort()
        return partitions
1220126
def list_of(cls):
    
    return lambda l: isinstance(l, list) and all(isinstance(x, cls) for x in l)
430296
def partition(a:Collection, sz:int)->List[Collection]:
    ""
    return [a[i:i+sz] for i in range(0, len(a), sz)]