Announcement

Collapse

Forum Guidelines

This forum is for finished source code that is working properly. If you have questions about this or any other source code, please post it in one of the Discussion Forums, not here.
See more
See less

HLib: Data Container Library

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • PBWin/PBCC HLib: Data Container Library

    Any comments, please post here.

    HLib is a library of many standard data containers; Array, List, Stack, Queue, Deque, Tree, Hash, more...

    public domain - use at own risk
    Downlaod: HLIb101.zip

    It's called 'H'Lib because all the containers are accessed with a Long Handle.

    Rules of the game:
    - The whole library consists of many Include files.
    - The 'HLib' library folder must be in the compiler's Include File Path. You can put HLib anywhere as long as it's in the compiler's Include Path.
    IDE Menu:Window/Options/Compiler/
    - Container must be created before use: h = ...New() 'return handle
    - Handle must be freed before it goes out of scope: h = ...Free(h) 'free container and null handle
    - Just include a container's source file to use it: #Include Once "StrArr.inc"

    All containers are controlled with a handle, so you can store/pass a container anywhere using its handle. You can store any container, as a handle, in any kind of Long data structure; Long Arrays.
    Each different container's handle is protected with a Hash Tag, code will only work with proper handle.

    Most containers support Clone, Store/Restore To/From String and Store/Restore To/From File.

    Naming convention; the include files use three or four letters to indicate data type and container type.
    Data Type:
    Byt = Byte
    Int = Integer
    Wrd = Word
    Lng = Long
    Dwd = Dword
    Sng = Single
    Dbl = Double
    Cur = Currency
    Cux = CurrencyX
    Ext = Extended
    Str = String
    WStr = WString
    Obj = Object
    Udt = UDT
    Container Type:
    Arr = Array
    Lst = List
    Stk = Stack
    Que = Queue
    Tre = Tree data structure
    MTre = Multi-Tree data structure
    Hsh = Hash Table
    MHsh = Multi-Hash Table
    Pri = Priority Queue

    LngArr = Long Array
    QudArr = Quad Array
    StrStk = String Stack
    WStrLst = WString List
    Some container support more than one data type.
    LngStrTree = Long/String Key/Value Balanced Binary Tree
    StrStrHsh = String/String Key/Value Hash Table

    All include files starting with HLib... are for internal use. They're included in all source files.

    Array Containers:
    - zero based index
    - ReDim automatic for all opperations; Add, Insert, Remove ... automatic
    - it's a handle - store in UDT, pass as Long, return as Long
    - extremely fast non-recursive Sort, Reverse
    - supports Binary Search and Binary Insert
    - stack and queue and deque functions
    - store/restore to/from String or File

    List Containers: Doubly Linked List
    - more efficient at Add, Insert, Remove than arrays
    - handle millions if items - really large arrays are out ot the question if you need to do a lot of inserts and removes
    - stack and queue and deque functions - a List is way better container for stack, queue and deque
    - store/restore to/from String or File

    Stack Containers:
    - deadly fast - uses buffering to cut down on memory allocations
    - an array is a poor stack for more than a few thousand items
    - the List container has excellent stack support
    - the dedicated stack container is fastest because of buffering
    - the stack container doesn't support Clone and Store/Restore

    Queue Containers:
    - deadly fast - uses buffering to cut down on memory allocations
    - an array is a really poor queue because you're removing the first value in the array every Pop
    - the List container has excellent queue support
    - the dedicated queue container is fastest because of buffering
    - the queue container doesn't support Clone and Store/Restore

    Tree Containers: AVL Balanced Binary Trees
    - one-to-one Key/Value relationship
    - Key must be unique
    - Value stored/retrieved/removed using lookup Key
    - Tree is always in Key order
    - traverse Tree in Key order
    - Long Key Trees are extremely fast, about as fast as a Long Hash
    - String and WString Trees are slower than a Hash Table
    - String and WString Trees may be set to compare case ignored, UCase or use a collation sequence string
    - store/restore to/from String or File

    Hash Table Containers:
    - one-to-one Key/Value relationship
    - Key must be unique
    - nulls not allowed in a String Key - OK in String Value
    - Value stored/retrieved/removed using lookup Key
    - Hash Table is in unpredictable order
    - store/restore to/from String or File

    UDT containers: not many implement yet...
    - UDT container are a little different from the other data types
    - UDT are stored as a null buffer, SizeOf(UDT)
    - you must use a pointer to Get/Set UDT data
    - any procedure adding a UDT to a container, stores a null buffer and returns a pointer to the buffer
    - Get procedures return the pointer address of the stored UDT
    - no Set procedures
    - Stacks and Queues - use Peek() to get UDT's date; Pop frees stored UDT and returns nothing
    - Compare: user must supply a callback function to call any method requiring a UDT comparison
    Last edited by Stanley Durham; 20 Jun 2012, 07:31 AM.
    stanthemanstan~gmail
    Dead Theory Walking
    Range Trie Tree
    HLib ~ Free Data Container Lib ~ Arrays, Lists, Stacks, Queues, Deques, Trees, Hashes
Working...
X