Skip to main content
AK (short for “Agner’s Kit”) is Ladybird’s custom standard library that provides fundamental data structures, smart pointers, string types, and utility classes. Every component in Ladybird depends on AK for basic functionality.

Core containers

AK provides efficient, modern C++ containers designed for browser development.

Vector

Vector<T> is a dynamic array similar to std::vector but with Ladybird-specific optimizations:
Key methods:
  • append() - Add element to end
  • prepend() - Add element to beginning
  • insert() - Insert at specific index
  • remove() - Remove by index
  • find() - Search for element
  • size() - Get element count

HashMap

HashMap<K, V> provides hash-based key-value storage:

Other containers

HashTable

Hash-based set for unique values

Optional

Type-safe nullable value wrapper

Variant

Type-safe union holding one of several types

Span

Non-owning view over contiguous data

Smart pointers

AK includes three main smart pointer types for memory safety.

OwnPtr and NonnullOwnPtr

Single-owner pointers for exclusive ownership:
NonnullOwnPtr cannot be null, making it perfect for return types and parameters where null is invalid. It’s equivalent to passing by reference (&) but with ownership transfer.

RefPtr and NonnullRefPtr

Reference-counted pointers for shared ownership:

WeakPtr

Non-owning pointer that automatically becomes null when the target is deleted:

String types

AK provides multiple string types optimized for different use cases.

String

UTF-8 encoded, reference-counted string with short string optimization:
String can store short strings (up to 23 bytes) inline without heap allocation, making it very efficient for common use cases.

StringView

Non-owning view over string data:

StringBuilder

Efficient string building through concatenation:

Error handling

ErrorOr<T>

Type-safe error handling without exceptions:

Result<T, E>

Generic result type for operations that can fail:

String formatting

AK provides printf-style formatting with compile-time checking.

Type specifiers

b binary, d decimal, x hex, s string, p pointer

Alignment

< left, > right, ^ center

Width & precision

{:10} min width, {:.4} precision/max

Utilities

Function

Type-erased callable wrapper:

Time

High-resolution time with duration types:

Badge

Restrict function access to specific classes:

Source location

  • Repository: ~/workspace/source/AK/
  • Key headers: Vector.h, HashMap.h, String.h, NonnullOwnPtr.h, RefPtr.h, Optional.h
  • Documentation: ~/workspace/source/Documentation/SmartPointers.md, ~/workspace/source/Documentation/StringFormatting.md
AK is designed to have zero dependencies - it doesn’t even depend on the C++ standard library for most operations. This makes it highly portable and predictable.