Uniot Docs
  • Introduction
  • Guides
    • Getting Started
    • Uniot Badge
    • Device Network
  • Foundations
    • Edge Logic Deployment
  • General Concepts
    • Primitives
    • Scripting
  • Platform
    • Dashboard
    • Sandbox
      • Visual Editor
        • Special
        • Logic
        • Math
        • Loops
        • Text
        • Variables
        • Functions
        • Primitives
      • Logger
      • Emulator
      • Control Panel
  • Advanced
    • Uniot Core
      • Scheduler
        • TaskScheduler
        • IExecutor
        • ISchedulerConnectionKit
        • Task
        • SchedulerTask
      • AppKit
        • AppKit
        • LispDevice
        • LispPrimitives
        • TopDevice
      • CBORWrapper
        • CBORObject
        • COSE
        • COSEMessage
        • ICOSESigner
      • Date
        • Date
        • SimpleNTP
      • EventBus
        • EventBus
        • IEventBusConnectionKit
        • DataChannels
        • EventEmitter
        • EventListener
        • EventEntity
        • CallbackEventListener
      • Hardware
        • Button
      • LispWrapper
        • DefaultPrimitives
        • LispHelper
        • PrimitiveExpeditor
        • unLisp
      • MQTTWrapper
        • CallbackMQTTDevice
        • MQTTDevice
        • MQTTKit
        • MQTTPath
      • Network
        • ConfigCaptivePortal
        • NetworkController
        • NetworkScheduler
      • Register
        • GpioRegister
        • ObjectRegister
        • ObjectRegisterRecord
        • Register
        • RegisterManager
        • RegisterManagerProxy
      • Storage
        • CBORStorage
        • CrashStorage
        • Storage
        • WifiStorage
      • Utils
        • Array
        • Bytes
        • ClearQueue
        • IterableQueue
        • LimitedQueue
        • GlobalBufferMemoryManager
        • Map
        • Singleton
        • TypeId
      • Credentials
    • Uniot Lisp
      • Language Description
      • Embedding Instructions
  • API
    • MQTT Convention
Powered by GitBook
On this page
  1. Advanced
  2. Uniot Core
  3. Utils

LimitedQueue

A Size-Capped Queue Implementation

The LimitedQueue class is a specialization of ClearQueue that adds functionality to limit the size of the queue. This class ensures that the queue does not grow beyond a specified size limit, providing better control over memory utilization.

Class Methods

Constructor:

  • LimitedQueue(): Initializes an empty LimitedQueue object with zero limit and size.

Accessor and Mutator Methods:

  • size_t limit(): Returns the current size limit of the queue.

  • size_t size(): Returns the current size of the queue (i.e., the number of elements it contains).

  • void limit(size_t limit): Sets the size limit for the queue. If the limit is set to a value less than the current size of the queue, excess elements are removed from the front of the queue.

Element Operations:

  • bool isFull(): Checks if the queue has reached its size limit.

  • void pushLimited(const T value): Pushes a new value into the queue, respecting the size limit. If adding the value would exceed the size limit, the oldest value in the queue is removed.

  • T popLimited(const T errorCode): Pops a value from the queue. Also decrements the size counter.

Internal Logic:

  • void applyLimit(): Removes excess elements from the front of the queue until it's within the size limit.

  • size_t calcSize(): Recalculates and updates the size of the queue by iterating over all elements. Useful in scenarios where there's a potential discrepancy between the mSize value and the actual number of elements.

Member Variables:

  • mLimit: Represents the size limit of the queue.

  • mSize: Represents the current number of elements in the queue.

Inherited Members:

As LimitedQueue is derived from ClearQueue, it inherits all functionalities of the ClearQueue class.

PreviousIterableQueueNextGlobalBufferMemoryManager

Last updated 1 year ago