// Limit generate LIMIT start, limit statement
6633
func (statement *Statement) Limit(limit int, start ...int) *Statement {
	statement.LimitN = limit
	if len(start) > 0 {
		statement.Start = start[0]
	}
	return statement
}
1172507
func LimitWriter(w io.Writer, n int64) io.Writer {
	return &limitedWriter{W: w, N: n}
}
1030464
func SequenceLimit(size int64, readers ...io.Reader) io.Reader {
	return io.LimitReader(
		io.MultiReader(readers...),
		size)
}
825371
func Limit(limit int) func(*index.Options) {
	return func(opts *index.Options) {
		opts.Limit = limit
	}
}
289766
func (e Output) WithLimit(n int) Output {
	e.limit = n
	return e
}
19463
func limit(aObj, bObj interface{}, max int) (string, string) {
	elidedPrefix := ""
	elidedASuffix := ""
	elidedBSuffix := ""
	a, b := fmt.Sprintf("%#v", aObj), fmt.Sprintf("%#v", bObj)

	if aObj != nil && bObj != nil {
		if aType, bType := fmt.Sprintf("%T", aObj), fmt.Sprintf("%T", bObj); aType != bType {
			a = fmt.Sprintf("%s (%s)", a, aType)
			b = fmt.Sprintf("%s (%s)", b, bType)
		}
	}

	for {
		switch {
		case len(a) > max && len(a) > 4 && len(b) > 4 && a[:4] == b[:4]:
			// a is too long, b has data, and the first several characters are the same
			elidedPrefix = "..."
			a = a[2:]
			b = b[2:]

		case len(b) > max && len(b) > 4 && len(a) > 4 && a[:4] == b[:4]:
			// b is too long, a has data, and the first several characters are the same
			elidedPrefix = "..."
			a = a[2:]
			b = b[2:]

		case len(a) > max:
			a = a[:max]
			elidedASuffix = "..."

		case len(b) > max:
			b = b[:max]
			elidedBSuffix = "..."

		default:
			// both are short enough
			return elidedPrefix + a + elidedASuffix, elidedPrefix + b + elidedBSuffix
		}
	}
}
1301481
func (t Term) Limit(args ...interface{}) Term {
	return constructMethodTerm(t, "Limit", p.Term_LIMIT, args, map[string]interface{}{})
}
862652
func (rl *RateLimiter) Limit() bool {
	// Calculate the number of ns that have passed since our last call
	now := unixNano()
	passed := now - atomic.SwapUint64(&rl.lastCheck, now)

	// Add them to our allowance
	rate := atomic.LoadUint64(&rl.rate)
	current := atomic.AddUint64(&rl.allowance, passed*rate)

	// Ensure our allowance is not over maximum
	if max := atomic.LoadUint64(&rl.max); current > max {
		atomic.AddUint64(&rl.allowance, max-current)
		current = max
	}

	// If our allowance is less than one unit, rate-limit!
	if current < rl.unit {
		return true
	}

	// Not limited, subtract a unit
	atomic.AddUint64(&rl.allowance, -rl.unit)
	return false
}
542889
func limit(limit int) scope {
	return scopeFunc(func(db *gorm.DB) *gorm.DB {
		return db.Limit(limit)
	})
}
782583
func (db *Database) Limit(limit int) *Database {
	db = db.clone()
	db.limit = limit
	return db
}
425793
func (self *Query) Limit(limit int) *Query {

	self.limit = limit

	return self
}
1261038
func (f *FilterOp) Limit(maxResults int) *FilterOp {
	f.LimitProp = &LimitFilter{Value: maxResults}
	return f
}
1247618
func (q *BaseQueryBuilder) BuildLimit(limit int64, offset int64) string {
	if limit < 0 && offset > 0 {
		// most DBMS requires LIMIT when OFFSET is present
		limit = 9223372036854775807 // 2^63 - 1
	}

	sql := ""
	if limit >= 0 {
		sql = fmt.Sprintf("LIMIT %v", limit)
	}
	if offset <= 0 {
		return sql
	}
	if sql != "" {
		sql += " "
	}
	return sql + fmt.Sprintf("OFFSET %v", offset)
}
188517
func (q *Query) Limit(amount uint) *Query {
	q.query.Limit(amount)
	return q
}
1360821
func (c *Collector) Limit(rule *LimitRule) error {
	return c.backend.Limit(rule)
}
1292121
func Limit(limit int) DeviceRequestOption {
	return func(opts *deviceRequestOpts) error {
		if limit > 1000 {
			return fmt.Errorf("Limit must not be higher than 1000")
		}
		opts.Limit = limit
		return nil
	}
}
804708
func (statement *Statement) Top(limit int) *Statement {
	statement.Limit(limit)
	return statement
}