// Get the last N elements of a list
175277
func (l *List) LastN(n int) (results []string, err error) {
	if l.name == nil {
		return nil, ErrDoesNotExist
	}
	return results, (*bbolt.DB)(l.db).View(func(tx *bbolt.Tx) error {
		bucket := tx.Bucket(l.name)
		if bucket == nil {
			return ErrBucketNotFound
		}
		var size int64
		bucket.ForEach(func(_, _ []byte) error {
			size++
			return nil // Continue ForEach
		})
		if size < int64(n) {
			return errors.New("Too few items in list")
		}
		// Ok, fetch the n last items. startPos is counting from 0.
		var (
			startPos = size - int64(n)
			i        int64
		)
		bucket.ForEach(func(_, value []byte) error {
			if i >= startPos {
				results = append(results, string(value))
			}
			i++
			return nil // Continue ForEach
		})
		return nil // Return from View function
	})
}
489429
func Get(n int) (ports []int) {
	ports, err := Free(n)
	if err != nil {
		panic(err)
	}

	return ports
}
1316250
func (s *Deque) Last() interface{} {
	s.RLock()
	defer s.RUnlock()

	item := s.container.Back()
	if item != nil {
		return item.Value
	} else {
		return nil
	}
}
837486
func (list *List) Get(idx int) (Value, error) {
	if idx > list.Length() {
		return nil, errors.New("index out of range")
	}
	return list.values[idx], nil
}
1179643
func (list *List) FirstN(n int) []string {
	if n < 1 || n >= list.length {
		return emptySlice()
	}
	return list.Slice(0, n-1)
}
268350
func (t *tree) Last() (k uint64, v *Container) {
	if q := t.last; q != nil {
		q := &q.d[q.c-1]
		k, v = q.k, q.v
	}
	return k, v
}
274383
func (a Args) Get(n int) string {
	if len(a) > n {
		return a[n]
	}
	return ""
}
691294
func (f Index) Last(prefix []byte) (i Item, err error) {
	it := f.db.NewIterator()
	defer it.Release()

	// get the next prefix in line
	// since leveldb iterator Seek seeks to the
	// next key if the key that it seeks to is not found
	// and by getting the previous key, the last one for the
	// actual prefix is found
	nextPrefix := incByteSlice(prefix)
	l := len(prefix)

	if l > 0 && nextPrefix != nil {
		it.Seek(append(f.prefix, nextPrefix...))
		it.Prev()
	} else {
		it.Last()
	}

	totalPrefix := append(f.prefix, prefix...)
	return f.itemFromIterator(it, totalPrefix)
}
347781
func (self *list) ForEach(f func(interface{})) {
	if self.IsNil() {
		return
	}
	f(self.Head())
	self.Tail().ForEach(f)
}
119443
func (list *List) Get(pos int) string {
	if pos < 0 || pos >= list.length {
		return ""
	}
	if pos == 0 {
		return list.first.Content
	}
	tmp := list.first
	for i := 0; i < pos; i++ {
		tmp = tmp.Next
	}
	return tmp.Content
}
711969
func (t *SecondaryTree) SeekLast() (e *SecondaryEnumerator, err error) {
	q := t.last
	if q == nil {
		return nil, io.EOF
	}

	return btEPool2.get(nil, true, q.c-1, q.d[q.c-1].k, q, t, atomic.LoadUint64(&t.ver)), nil
}
810798
func LastIndexOfInt64(a []int64, x int64) int {
	return lastIndexOf(len(a), func(i int) bool { return a[i] == x })
}
740693
func (iter *Iterator) Last() bool {
	// Seek the limit key if the iterator was created with one.  This will
	// result in the first key smaller than the limit key, or an exhausted
	// iterator if no such key exists.
	iter.isNew = false
	if iter.limitKey != nil {
		return iter.seek(iter.limitKey, false, false)
	}

	// The highest key is in the right-most node.
	iter.parents = parentStack{}
	for node := iter.root; node != nil; node = node.right {
		if node.right == nil {
			iter.node = node
			return true
		}
		iter.parents.Push(node)
	}
	return false
}
868394
func Get(n int) string {
	b := make([]rune, n)
	for i := range b {
		b[i] = Alphabet[rand.Intn(len(Alphabet))]
	}

	return string(b)
}
403898
func (s IntSet) List() []int {
	res := make([]int, 0, len(s))
	for key := range s {
		res = append(res, key)
	}
	sort.IntSlice(res).Sort()
	return res
}
187293
func (c *Cursor) Last() (key []byte, value []byte) {
	_assert(c.bucket.tx.db != nil, "tx closed")
	c.stack = c.stack[:0]
	p, n := c.bucket.pageNode(c.bucket.root)
	ref := elemRef{page: p, node: n}
	ref.index = ref.count() - 1
	c.stack = append(c.stack, ref)
	c.last()
	k, v, flags := c.keyValue()
	if (flags & uint32(bucketLeafFlag)) != 0 {
		return k, nil
	}
	return k, v
}
246489
func (p *Preemptor) getNumPreemptions(alloc *structs.Allocation) int {
	c, ok := p.currentPreemptions[structs.NewNamespacedID(alloc.JobID, alloc.Namespace)][alloc.TaskGroup]
	if !ok {
		return 0
	}
	return c
}