code: func (h *receivedPacketHistory) ReceivedPacket(p protocol.PacketNumber) error {
  	if h.ranges.Len() >= protocol.MaxTrackedReceivedAckRanges {
  		return errTooManyOutstandingReceivedAckRanges
  	}
  
  	if h.ranges.Len() == 0 {
  		h.ranges.PushBack(utils.PacketInterval{Start: p, End: p})
  		return nil
  	}
  
  	for el := h.ranges.Back(); el != nil; el = el.Prev() {
  		// p already included in an existing range. Nothing to do here
  		if p >= el.Value.Start && p <= el.Value.End {
  			return nil
  		}
  
  		var rangeExtended bool
  		if el.Value.End == p-1 { // extend a range at the end
  			rangeExtended = true
  			el.Value.End = p
  		} else if el.Value.Start == p+1 { // extend a range at the beginning
  			rangeExtended = true
  			el.Value.Start = p
  		}
  
  		// if a range was extended (either at the beginning or at the end, maybe it is possible to merge two ranges into one)
  		if rangeExtended {
  			prev := el.Prev()
  			if prev != nil && prev.Value.End+1 == el.Value.Start { // merge two ranges
  				prev.Value.End = el.Value.End
  				h.ranges.Remove(el)
  				return nil
  			}
  			return nil // if the two ranges were not merge, we're done here
  		}
  
  		// create a new range at the end
  		if p > el.Value.End {
  			h.ranges.InsertAfter(utils.PacketInterval{Start: p, End: p}, el)
  			return nil
  		}
  	}
  
  	// create a new range at the beginning
  	h.ranges.InsertBefore(utils.PacketInterval{Start: p, End: p}, h.ranges.Front())
  
  	return nil
  }
docs: // ReceivedPacket registers a packet with PacketNumber p and updates the ranges