// Iterate iterates all available blocks that matches the provided hash, reads
// them into buf, and calls the iterator function. The iterator function should
// return whether it wishes to continue iterating.
779726
func (h *Finder) Iterate(hash uint32, buf []byte, iterFunc func(int64) bool) (bool, error) {
	if h == nil || hash == 0 || len(buf) != h.size {
		return false, nil
	}

	for _, offset := range h.offsets[hash] {
		_, err := h.reader.Seek(offset, io.SeekStart)
		if err != nil {
			return false, err
		}
		_, err = h.reader.Read(buf)
		if err != nil {
			return false, err
		}
		if !iterFunc(offset) {
			return true, nil
		}
	}
	return false, nil
}
460273
func (engine *Engine) Iterate(bean interface{}, fun IterFunc) error {
	session := engine.NewSession()
	defer session.Close()
	return session.Iterate(bean, fun)
}
1122017
func (is *InputStruct) Iterator(index int) (sophie.IterateCloser, error) {
	if is.IteratorF != nil {
		return is.IteratorF(index)
	}
	return &sophie.IterateCloserStruct{}, nil
}
1364802
func (p *MemoryPool) Iterator() *PoolIterator {
	p.mutex.Lock()
	defer p.mutex.Unlock()

	keys := make([]string, len(p.entries))
	i := 0
	for k := range p.entries {
		keys[i] = k
		i++
	}

	return &PoolIterator{pool: p, keys: keys, current: 0}
}
1217855
func (s Set) Iter(cb func(string) bool) {
	for k := range s {
		if !cb(k) {
			break
		}
	}
}
763733
func (c *ExpireCache) Each(concurrent int, callBack func(key interface{}, value interface{}) error) []error {
	fanOut := NewFanOut(concurrent)
	keys := c.Keys()

	for _, key := range keys {
		fanOut.Run(func(key interface{}) error {
			c.mutex.Lock()
			record, ok := c.cache[key]
			c.mutex.Unlock()
			if !ok {
				return errors.Errorf("Each() - key '%+v' disapeared "+
					"from cache during iteration", key)
			}

			err := callBack(key, record.Value)
			if err != nil {
				return err
			}

			c.mutex.Lock()
			if record.ExpireAt.Before(time.Now().UTC()) {
				delete(c.cache, key)
			}
			c.mutex.Unlock()
			return nil
		}, key)
	}

	// Wait for all the routines to complete
	errs := fanOut.Wait()
	if errs != nil {
		return errs
	}

	return nil
}
1363655
func (in DirInput) Iterator(index int) (sophie.IterateCloser, error) {
	infos, err := in.Fs.ReadDir(in.Path)
	if err != nil {
		return nil, err
	}

	return NewReader(sophie.FsPath(in).Join(infos[index].Name()))
}
10000
func (bl *BitList) IterateBytes() <-chan byte {
	res := make(chan byte)

	go func() {
		c := bl.count
		shift := 24
		i := 0
		for c > 0 {
			res <- byte((bl.data[i] >> uint(shift)) & 0xFF)
			shift -= 8
			if shift < 0 {
				shift = 24
				i++
			}
			c -= 8
		}
		close(res)
	}()

	return res
}
731191
func Iterate(p *dt.Plugin, label string, opts OptsIterate) []dt.State {
	if len(label) == 0 {
		label = "__iterableStart"
	}
	return []dt.State{
		{
			Label: label,
			OnEntry: func(in *dt.Msg) string {
				var ss []string
				mem := p.GetMemory(in, opts.IterableMemKey)
				if len(mem.Val) == 0 {
					mem.Val = []byte(`[]`)
				}
				err := json.Unmarshal(mem.Val, &ss)
				if err != nil {
					p.Log.Info("failed to get iterable memory.", err)
					return ""
				}
				if len(ss) == 0 {
					return "I'm afraid I couldn't find any results like that."
				}
				var idx int64
				if p.HasMemory(in, keySelection) {
					idx = p.GetMemory(in, keySelection).Int64() + 1
				}
				if idx >= int64(len(ss)) {
					return "I'm afraid that's all I have."
				}
				p.SetMemory(in, keySelection, idx)
				return fmt.Sprintf("How about %s?", ss[idx])
			},
			OnInput: func(in *dt.Msg) {
				yes, err := language.ExtractYesNo(in.Sentence)
				if err != nil {
					// Yes/No answer not found
					return
				}
				if yes {
					idx := p.GetMemory(in, keySelection).Int64()
					p.SetMemory(in, opts.ResultMemKeyIdx, idx)
					return
				}
				// TODO handle "next", "something else", etc.
			},
			Complete: func(in *dt.Msg) (bool, string) {
				if p.HasMemory(in, opts.ResultMemKeyIdx) {
					return true, ""
				}
				return false, p.SM.ReplayState(in)
			},
		},
	}
}
249946
func (it *iterator) Next() bool {
	// If the iterator was not yet initialized, do it now
	if !it.inited {
		it.inited = true
		return len(it.keys) > 0
	}
	// Iterator already initialize, advance it
	if len(it.keys) > 0 {
		it.keys = it.keys[1:]
		it.values = it.values[1:]
	}
	return len(it.keys) > 0
}
318420
func (iter *bitArrayIterator) Value() (uint64, block) {
	return uint64(iter.index), iter.ba.blocks[iter.index]
}
444676
func (kv *KV) Iterator(f func([]byte, []byte) bool) error {
	return kv.db.View(func(tx *bolt.Tx) error {
		tx.Bucket(kv.table).ForEach(func(k, v []byte) error {
			if k == nil || f(k, v) {
				return nil
			}
			return errors.New("stop")
		})
		return nil
	})
}
176142
func (c *IterateChain) All() ([]Value, error) {
	c.start()
	defer c.end()
	done := c.ctx.Done()
	var out []Value
iteration:
	for c.next() {
		select {
		case <-done:
			break iteration
		default:
		}
		out = append(out, c.it.Result())
		for c.nextPath() {
			select {
			case <-done:
				break iteration
			default:
			}
			out = append(out, c.it.Result())
		}
	}
	return out, c.it.Err()
}
419203
func (s *SkipList) Iterator() Iterator {
	return &iter{
		current: s.header,
		list:    s,
	}
}
931212
func (block *BestBlock) Hash() *chainhash.Hash {
	// Caller should check hash instead of error
	hash, _ := chainhash.NewHashFromStr(block.HashStr())
	return hash
}
436393
func (s *BufferStore) Iter(k Key, upperBound Key) (Iterator, error) {
	bufferIt, err := s.MemBuffer.Iter(k, upperBound)
	if err != nil {
		return nil, err
	}
	retrieverIt, err := s.r.Iter(k, upperBound)
	if err != nil {
		return nil, err
	}
	return NewUnionIter(bufferIt, retrieverIt, false)
}
77965
func (iter *Iterator) Key() *Slice {
	var cLen C.size_t
	cKey := C.rocksdb_iter_key(iter.c, &cLen)
	if cKey == nil {
		return nil
	}
	return &Slice{cKey, cLen, true}
}