PBXB64 H-Lib Container

Vollständige native H-Lib-Sammlung PBXB64 V21

PBXB64 V21 integriert 22 H-Lib-Kernfamilien plus den synchronisierten Safe-Wrapper als erstklassige verwaltete Datentypen mit mehr als 125 typisierten Varianten. Das Spektrum umfasst Arr, Stk, Que, Lst, Str, 2D, Hsh, Tre, DTre, Tri, Heap, Deque, Set, Graph, Multiset, Union-Find, LRU Cache, Ring, SkipList, B+ Tree, Quadtree, Bloom Filter und Safe-Strukturen. Sie verwenden Punktmethoden, benötigen keine externe Bibliothek und werden beim Scope-Ende automatisch bereinigt.

Die folgenden Abschnitte zeigen repräsentative Collection-Muster. Die Datentyp-Referenz erklärt Familiennamen, PB-Wertpräfixe und die verwaltete Lebensdauer.

Hash-Tabelle (SSSHSH) - Assoziativer Schlüssel-Wert-Speicher

Hash-basierter assoziativer Container mit String-Schlüsseln und String-Werten. O(1) Suche im Durchschnitt. Vollständige CRUD-Operationen.

SSSHSH - Schlüssel-Wert-Speicher
#COMPILE EXE #DIM ALL FUNCTION PBMAIN() AS LONG LOCAL person AS SSSHSH ' hash table: STRING key -> STRING value person = person.New person.Put "name", "Alice" person.Put "age", "30" person.Put "city", "Berlin" PRINT "Name: "; person.Get("name") PRINT "Age: "; person.Get("age") PRINT "Zip: "; person.TryGet("zip", "(none)") ' default for a missing key person.Remove "age" PRINT "Has age:"; person.Contains("age") ' 0 PRINT "Count: "; person.Count ' 2 person.Final ' release (also automatic at scope exit) FUNCTION = 0 END FUNCTION

SSSHSH-API (String-Schlüssel auf String-Wert): .Put, .Get, .TryGet, .Contains, .Remove, .Count, .Clear, .Keys, .Values, .Final. Deklaration mit LOCAL x AS SSSHSH, die Tabelle wird mit x = x.New angelegt.

LNARR - Dynamisches Array

Dynamisches Array mit automatischer Vergrößerung. O(1) amortisiertes Anhängen.

LNARR - Dynamisches Array
#COMPILE EXE #DIM ALL FUNCTION PBMAIN() AS LONG LOCAL v AS LNARR ' growable array of 64-bit integers LOCAL i AS LONG LOCAL n AS QUAD v = v.New v.Push 30 v.Push 10 v.Push 20 PRINT "Count: "; v.Count ' 3 PRINT "Item 1: "; v.Get(1) ' PB index is 1-based -> 30 v.Set 2, 15 ' overwrite item 2 v.Ins 1, 99 ' insert 99 at index 1 v.Del 1 ' delete it again v.Sort ' ascending order FOR EACH n IN v PRINT n; NEXT PRINT PRINT "Popped: "; v.Pop ' last element (30) v.Final FUNCTION = 0 END FUNCTION

LNARR-API (Array aus 64-Bit-Ganzzahlen): .Push, .Add, .Pop, .Peek, .Get, .Set, .Ins, .Del, .Count, .IndexOf, .Contains, .Sort, .SortDesc, .Reverse, .Clear sowie FOR EACH. Indizes beginnen bei 1, wie in PowerBASIC.

AVL-Baum (LNLNTRE) - Ausgeglichene Suche

Selbstausgleichender binärer (AVL-)Suchbaum. O(log n) Einfügen, Löschen, Suchen.

LNLNTRE - Geordneter Schlüssel-Wert-Baum
#COMPILE EXE #DIM ALL FUNCTION PBMAIN() AS LONG LOCAL t AS LNLNTRE ' ordered tree: LONG key -> LONG value t = t.New t.Put 50, 500 t.Put 30, 300 t.Put 70, 700 t.Put 20, 200 t.Put 40, 400 PRINT "Contains 30: "; t.Contains(30) ' non-zero PRINT "Min: "; t.Min ' 20 PRINT "Max: "; t.Max ' 70 PRINT "Floor(35): "; t.Floor(35) ' 30 PRINT "Ceil(35): "; t.Ceil(35) ' 40 t.Remove 30 PRINT "Contains 30: "; t.Contains(30) ' 0 PRINT "Count: "; t.Count ' 4 t.Final FUNCTION = 0 END FUNCTION

LNLNTRE-API (LONG-Schlüssel auf LONG-Wert, in Schlüsselreihenfolge gehalten): .Put, .Get, .TryGet, .Remove, .Contains, .Min, .Max, .Floor, .Ceil, .Keys, .Values, .Count, .Clear.

Linked List - LIFO / FIFO

Doppelt verlinkte Liste mit O(1) push/pop an beiden Enden.

Linked List - Warteschlange / Stapel
#COMPILE EXE #DIM ALL FUNCTION PBMAIN() AS LONG LOCAL lst AS LNLST ' doubly-linked list of LONG values LOCAL node AS QUAD lst = lst.New lst.Add 20 ' [20] lst.Add 30 ' [20, 30] lst.AddHead 10 ' [10, 20, 30] PRINT "Head: "; lst.GetHead PRINT "Tail: "; lst.GetTail PRINT "Count: "; lst.Count ' walk the list with node cursors node = lst.First DO WHILE node <> 0 PRINT lst.Value(node); node = lst.Next(node) LOOP PRINT PRINT "Removed head: "; lst.RemoveHead PRINT "New head: "; lst.GetHead lst.Final FUNCTION = 0 END FUNCTION

LNLST-API: .Add, .AddHead, .GetHead, .GetTail, .RemoveHead, .RemoveTail, .First, .Next, .Prev, .Value, .InsAfter, .InsBefore, .Remove, .Count, .Clear. Die Liste wird mit .First, .Next und .Value durchlaufen.

Deque - Doppelseitige Warteschlange

Effiziente doppelseitige Warteschlange mit O(1) Operationen an beiden Enden.

Deque - Schnell an beiden Enden
#COMPILE EXE #DIM ALL FUNCTION PBMAIN() AS LONG LOCAL d AS LNDEQUE ' double-ended queue of LONG values d = d.New d.PushFront 20 d.PushBack 30 d.PushFront 10 PRINT "Front: "; d.PeekFront ' 10 PRINT "Back: "; d.PeekBack ' 30 PRINT "Count: "; d.Count ' 3 PRINT "PopFront: "; d.PopFront ' 10 PRINT "PopBack: "; d.PopBack ' 30 PRINT "Left: "; d.Count ' 1 d.Final FUNCTION = 0 END FUNCTION

LNDEQUE-API: .PushFront, .PushBack, .PopFront, .PopBack, .PeekFront, .PeekBack, .Count, .Empty, .Clear.

Set & Hash Table

Sortiertes Set eindeutiger 32-Bit-Schlüssel (LNSET) und Hash-Tabelle (LNLNHSH, O(1) im Durchschnitt).

Set & Hash Table
#COMPILE EXE #DIM ALL FUNCTION PBMAIN() AS LONG LOCAL s AS LNSET ' sorted set of unique LONG values LOCAL h AS LNLNHSH ' hash table: LONG key -> LONG value s = s.New s.Add 3 s.Add 1 s.Add 2 s.Add 3 ' ignored - duplicate PRINT "Set count: "; s.Count ' 3 PRINT "Smallest: "; s.First ' 1 PRINT "After 1: "; s.Next(1) ' 2 PRINT "Has 2: "; s.Contains(2) ' non-zero h = h.New h.Put 1, 100 h.Put 2, 200 PRINT "Hash 2 -> "; h.Get(2) ' 200 PRINT "Hash 9 -> "; h.TryGet(9, 0) ' 0 (default) s.Final : h.Final FUNCTION = 0 END FUNCTION

LNSET-API: .Add, .Remove, .Contains, .Count, .First, .Next, .ToArray, .Clear.
LNLNHSH-API: .Put, .Get, .TryGet, .Remove, .Contains, .Keys, .Count, .Clear.

Probieren Sie es selbst

CLI - kompilieren und ausführen
REM Map-Beispiel PBXB64 test_map.pb -o test_map.exe test_map.exe REM Vector-Beispiel PBXB64 test_vector.pb -o test_vector.exe test_vector.exe REM Alle Container PBXB64 test_containers.pb -o test_containers.exe test_containers.exe

Alle Testdateien befinden sich in examples/basic/ - kompilieren und ausführen zum Verifizieren.

Zurück zur Feature-Liste