Incrementally return lists of elements in a set. Also return a cursor
        indicating the scan position.

        ``match`` allows for filtering the keys by pattern

        ``count`` allows for hint the minimum number of returns
13600
def sscan(self, name, cursor=0, match=None, count=None):
        
        pieces = [name, cursor]
        if match is not None:
            pieces.extend([Token.get_token('MATCH'), match])
        if count is not None:
            pieces.extend([Token.get_token('COUNT'), count])
        return self.execute_command('SSCAN', *pieces)
818616
def get_next_item(iterable):
    """"""
    try: x = iterable.next()
    except StopIteration: x = None
    except AttributeError: x = None
    return x
554982
def _extract_all_sets_from_list(
            self):
        
        self.log.debug('starting the ``_extract_all_sets_from_list`` method')

        from HMpTy import HTM
        mesh = HTM(
            depth=12,
            log=self.log
        )

        matchIndices1, matchIndices2, seps = mesh.match(
            ra1=self.ra,
            dec1=self.dec,
            ra2=self.ra,
            dec2=self.dec,
            radius=self.radius,
            maxmatch=0,  # 1 = match closest 1, 0 = match all,
            convertToArray=self.convertToArray
        )

        anchorIndicies = []
        childIndicies = []
        allMatches = []
        thisMatch = None
        for m1, m2, s in zip(matchIndices1, matchIndices2, seps):
            if m1 not in anchorIndicies and m1 not in childIndicies:
                if thisMatch:
                    allMatches.append(thisMatch)
                thisMatch = [self.sourceList[m1]]
                anchorIndicies.append(m1)
            if m2 not in anchorIndicies and m2 not in childIndicies:
                childIndicies.append(m2)
                thisMatch.append(self.sourceList[m2])
        if thisMatch:
            allMatches.append(thisMatch)

        self.log.debug('completed the ``_extract_all_sets_from_list`` method')
        return allMatches
914016
def results_iterator(self, scan_id, pop_res):
        
        if pop_res:
            result_aux = self.scans_table[scan_id]['results']
            self.scans_table[scan_id]['results'] = list()
            return iter(result_aux)

        return iter(self.scans_table[scan_id]['results'])
316883
def get_more(collection_name, num_to_return, cursor_id):
    
    data = __ZERO
    data += bson._make_c_string(collection_name)
    data += struct.pack("<i", num_to_return)
    data += struct.pack("<q", cursor_id)
    return __pack_message(2005, data)
348733
def zscan(self, key, cursor=0, match=None, count=None):
        """"""
        args = []
        if match is not None:
            args += [b'MATCH', match]
        if count is not None:
            args += [b'COUNT', count]
        fut = self.execute(b'ZSCAN', key, cursor, *args)

        def _converter(obj):
            return (int(obj[0]), pairs_int_or_float(obj[1]))

        return wait_convert(fut, _converter)
638458
def find_next_matching_line(self, match_func, count=1):
        
        result = None

        for index, line in enumerate(self.lines[self.cursor_position_row + 1:]):
            if match_func(line):
                result = 1 + index
                count -= 1

            if count == 0:
                break

        return result
1362516
def iscan(self, *, match=None, count=None):
        
        return _ScanIter(lambda cur: self.scan(cur,
                                               match=match, count=count))
1019400
def items_iter(self, limit):
        '''
        '''

        pages = (page.get() for page in self._pages())
        items = itertools.chain.from_iterable(
            (p[self.ITEM_KEY] for p in pages)
        )
        if limit is not None:
            items = itertools.islice(items, limit)
        return items
1262288
def _search(self, search_state, include_current_position=False, count=1):
        
        assert isinstance(search_state, SearchState)
        assert isinstance(count, int) and count > 0

        text = search_state.text
        direction = search_state.direction
        ignore_case = search_state.ignore_case()

        def search_once(working_index, document):
            """
            Do search one time.
            Return (working_index, document) or `None`
            """
            if direction == IncrementalSearchDirection.FORWARD:
                # Try find at the current input.
                new_index = document.find(
                   text, include_current_position=include_current_position,
                   ignore_case=ignore_case)

                if new_index is not None:
                    return (working_index,
                            Document(document.text, document.cursor_position + new_index))
                else:
                    # No match, go forward in the history. (Include len+1 to wrap around.)
                    # (Here we should always include all cursor positions, because
                    # it's a different line.)
                    for i in range(working_index + 1, len(self._working_lines) + 1):
                        i %= len(self._working_lines)

                        document = Document(self._working_lines[i], 0)
                        new_index = document.find(text, include_current_position=True,
                                                  ignore_case=ignore_case)
                        if new_index is not None:
                            return (i, Document(document.text, new_index))
            else:
                # Try find at the current input.
                new_index = document.find_backwards(
                    text, ignore_case=ignore_case)

                if new_index is not None:
                    return (working_index,
                            Document(document.text, document.cursor_position + new_index))
                else:
                    # No match, go back in the history. (Include -1 to wrap around.)
                    for i in range(working_index - 1, -2, -1):
                        i %= len(self._working_lines)

                        document = Document(self._working_lines[i], len(self._working_lines[i]))
                        new_index = document.find_backwards(
                            text, ignore_case=ignore_case)
                        if new_index is not None:
                            return (i, Document(document.text, len(document.text) + new_index))

        # Do 'count' search iterations.
        working_index = self.working_index
        document = self.document
        for _ in range(count):
            result = search_once(working_index, document)
            if result is None:
                return  # Nothing found.
            else:
                working_index, document = result

        return (working_index, document.cursor_position)
1208392
def collect(cls, result_key, func):
        
        def scanner(self, obj):
            if not getattr(self, result_key, None):
                setattr(self, result_key, [])
            rv = func(obj)
            if rv:
                getattr(self, result_key).append(rv)

        cls._scan(result_key, scanner)
687554
def _scan(self, type):
        
        tok = self._scanner.token(self._pos, frozenset([type]))
        self._char_pos = tok[0]
        if tok[2] != type:
            raise SyntaxError("SyntaxError[@ char %s: %s]" % (repr(tok[0]), "Trying to find " + type))
        self._pos += 1
        return tok[3]
882846
def scan(pattern, string, *args, **kwargs):
    
    return compile(pattern, *args, **kwargs).scan(string)
499217
def search(self, pattern, count=None):
        
        return self._scan(match=pattern, count=count)
185176
def _find_match(ele, lst):
    '''
    
    '''
    for _ele in lst:
        for match_key in _MATCH_KEYS:
            if _ele.get(match_key) == ele.get(match_key):
                return ele
455043
def keys(pattern = SCAN_PATTERN, count = DEFAULT_COUNT)
      return redis(&:keys) if pattern.nil?

      redis { |conn| conn.scan_each(match: prefix(pattern), count: count).to_a }
    end
647928
def items(self, match="*", count=1000):
        
        for field, value in self._client.hscan_iter(
          self.key_prefix, match=match, count=count):
            yield self._decode(field), self._loads(value)