PBXB64 H-Lib Containers
7 Container Types
PBXB64 Addition
PBXB64 ships a full STL-equivalent container library - Maps, Vectors, Red-Black Trees, Linked Lists, Deques, Sets, and Hash Tables. Every container is fully generic, supports key-value pairs, and provides a complete API. No external libraries needed.
Map - Associative Key-Value Storage
Ordered associative container. O(log n) lookup. Full CRUD operations.
Map - Key-value storage
FUNCTION PBMAIN() AS LONG
LOCAL m AS MAP
MAP SET m, "name", "Alice"
MAP SET m, "age", "30"
MAP SET m, "city", "Berlin"
PRINT "Name: "; MAP GET$(m, "name")
PRINT "Age: "; MAP GET$(m, "age")
MAP REMOVE m, "age"
PRINT "Keys: "; MAP KEYS(m)
FUNCTION = 0
END FUNCTION
MAP API: MAP SET, MAP GET, MAP REMOVE, MAP KEYS, MAP VALUES, MAP COUNT, MAP EXISTS, MAP CLEAR, MAP ITER.
Vector - Dynamic Array
Dynamic array with automatic resize. O(1) amortized append.
Vector - Dynamic array
FUNCTION PBMAIN() AS LONG
LOCAL v AS VECTOR
VECTOR PUSH v, "First"
VECTOR PUSH v, "Second"
VECTOR PUSH v, "Third"
PRINT "Count: "; VECTOR COUNT(v)
PRINT "Item 0: "; VECTOR GET$(v, 0)
VECTOR SET v, 1, "Updated"
VECTOR REMOVE v, 2
PRINT "All: "; VECTOR JOIN$(v, ", ")
FUNCTION = 0
END FUNCTION
VECTOR API: VECTOR PUSH, VECTOR POP, VECTOR GET, VECTOR SET, VECTOR COUNT, VECTOR REMOVE, VECTOR CLEAR, VECTOR JOIN, VECTOR FIND, VECTOR SORT, VECTOR REVERSE.
Red-Black Tree - Balanced Binary Search
Self-balancing binary search tree. O(log n) insert, delete, find.
Red-Black Tree - Ordered set
FUNCTION PBMAIN() AS LONG
LOCAL t AS RBTREE
RBTREE INSERT t, 50
RBTREE INSERT t, 30
RBTREE INSERT t, 70
RBTREE INSERT t, 20
RBTREE INSERT t, 40
PRINT "Contains 30: "; RBTREE CONTAINS(t, 30)
PRINT "Min: "; RBTREE MIN(t)
PRINT "Max: "; RBTREE MAX(t)
RBTREE REMOVE t, 30
PRINT "Contains 30: "; RBTREE CONTAINS(t, 30)
FUNCTION = 0
END FUNCTION
RBTREE API: RBTREE INSERT, RBTREE REMOVE, RBTREE CONTAINS, RBTREE MIN, RBTREE MAX, RBTREE COUNT, RBTREE CLEAR, RBTREE INORDER.
Linked List - LIFO / FIFO
Doubly-linked list with O(1) push/pop at both ends.
Linked List - Queue / Stack
FUNCTION PBMAIN() AS LONG
LOCAL lst AS LIST
LIST PUSH_FRONT lst, "A"
LIST PUSH_BACK lst, "B"
LIST PUSH_FRONT lst, "C"
PRINT "Front: "; LIST FRONT$(lst)
PRINT "Back: "; LIST BACK$(lst)
PRINT "Count: "; LIST COUNT(lst)
LIST POP_FRONT lst
PRINT "After pop: "; LIST FRONT$(lst)
FUNCTION = 0
END FUNCTION
LIST API: LIST PUSH_FRONT, LIST PUSH_BACK, LIST POP_FRONT, LIST POP_BACK, LIST FRONT, LIST BACK, LIST COUNT, LIST CLEAR, LIST INSERT, LIST REMOVE.
Deque - Double-Ended Queue
Efficient double-ended queue with O(1) operations at both ends and random access.
Deque - Fast at both ends
FUNCTION PBMAIN() AS LONG
LOCAL d AS DEQUE
DEQUE PUSH_FRONT d, "First"
DEQUE PUSH_BACK d, "Last"
DEQUE PUSH_FRONT d, "Front"
PRINT "Front: "; DEQUE FRONT$(d)
PRINT "Back: "; DEQUE BACK$(d)
PRINT "Item 1: "; DEQUE GET$(d, 1)
FUNCTION = 0
END FUNCTION
DEQUE API: DEQUE PUSH_FRONT, DEQUE PUSH_BACK, DEQUE POP_FRONT, DEQUE POP_BACK, DEQUE FRONT, DEQUE BACK, DEQUE GET, DEQUE SET, DEQUE COUNT, DEQUE CLEAR.
Set & Hash Table
Ordered set (tree-based) and unordered hash table (O(1) average).
Set & Hash Table
FUNCTION PBMAIN() AS LONG
LOCAL s AS SET
LOCAL h AS HASHTABLE
' Ordered Set
SET ADD s, "apple"
SET ADD s, "banana"
SET ADD s, "apple" ' Ignored - duplicate
PRINT "Set count: "; SET COUNT(s)
' Hash Table
HASH PUT h, "key1", "value1"
HASH PUT h, "key2", "value2"
PRINT "Hash key1: "; HASH GET$(h, "key1")
FUNCTION = 0
END FUNCTION
SET API: SET ADD, SET REMOVE, SET CONTAINS, SET COUNT, SET CLEAR, SET UNION, SET INTERSECT, SET DIFF.
HASH API: HASH PUT, HASH GET, HASH REMOVE, HASH CONTAINS, HASH COUNT, HASH CLEAR, HASH KEYS.
Try it yourself
CLI - compile and run
REM Map example
PBXB64 test_map.pb -o test_map.exe
test_map.exe
REM Vector example
PBXB64 test_vector.pb -o test_vector.exe
test_vector.exe
REM All containers
PBXB64 test_containers.pb -o test_containers.exe
test_containers.exe
All test files are in examples/basic/ - compile and run to verify.