class_docstr: A set-like where the `pop` method returns the smallest item, as sorted by an
  arbitrary key function. Ties are broken by oldest first.
  
  Values must be compatible with :mod:`weakref`.
  
  Parameters
  ----------
  key: Callable
      A function that takes a single element of the collection as a parameter and
      returns a sorting key. The key does not need to be hashable and does not need to
      support :mod:`weakref`.
  
  Note
  ----
  The key returned for each element should not to change over time. If it does, the
  position in the heap won't change, even if the element is re-added, and it *may* not
  change even if it's discarded and then re-added later.
class_docstr_tok: ["A","set-like","where","the","`","pop","`","method","returns","the","smallest","item",",","as","sorted","by","an","arbitrary","key","function",".","Ties","are","broken","by","oldest","first",".","Values","must","be","compatible","with",":","mod",":","`","weakref","`",".","Parameters","--","--","--","--","--","key",":","Callable","A","function","that","takes","a","single","element","of","the","collection","as","a","parameter","and","returns","a","sorting","key",".","The","key","does","not","need","to","be","hashable","and","does","not","need","to","support",":","mod",":","`","weakref","`",".","Note","--","--","The","key","returned","for","each","element","should","not","to","change","over","time",".","If","it","does",",","the","position","in","the","heap","wo","n't","change",",","even","if","the","element","is","re-added",",","and","it","*","may","*","not","change","even","if","it","'s","discarded","and","then","re-added","later","."]
docstr: Iterate over the n smallest elements without removing them.
  This is O(1) for n == 1; O(n*logn) otherwise.
docstr_tok: ["Iterate","over","the","n","smallest","elements","without","removing","them",".","This","is","O","(","1",")","for","n","==","1",";","O","(","n","*","logn",")","otherwise","."]
code: def peekn(self, n: int) -> Iterator[T]:
      """Iterate over the n smallest elements without removing them.
      This is O(1) for n == 1; O(n*logn) otherwise.
      """
      if n <= 0 or not self:
          return  # empty iterator
      if n == 1:
          yield self.peek()
      else:
          # NOTE: we could pop N items off the queue, then push them back.
          # But copying the list N times is probably slower than just sorting it
          # with fast C code.
          # If we had a `heappop` that sliced the list instead of popping from it,
          # we could implement an optimized version for small `n`s.
          yield from itertools.islice(self.sorted(), n)
  
imports: from __future__ import annotations
  import heapq
  import itertools
  import weakref
  from collections import OrderedDict, UserDict
  from collections.abc import Callable, Hashable, Iterable, Iterator, Mapping, MutableSet
  from typing import Any, TypeVar, cast
label_desc: Use image node_id 10 for calling the HeapSet obj's underlying member method code with example usage: obj.peekn(n) without return types