AuthManager is the user registry for LYNX. It maintains in-memory collections for all three user types — passengers, drivers, and admins — and persists them through FileManager on every state change. Two parallel hash tables (Documentation Index
Fetch the complete documentation index at: https://mintlify.com/yeremyacuna/LYNX/llms.txt
Use this file to discover all available pages before exploring further.
hashPasajeros and hashConductores) shadow the linked lists so that any lookup by DNI runs in O(1) average time instead of O(n).
Internal State
| Field | Type | Purpose |
|---|---|---|
passengerList | LinkedList<Passenger>* | Primary ordered list of all passengers |
driverList | LinkedList<Driver>* | Primary ordered list of all drivers |
adminList | LinkedList<FileManager::AdminPreview>* | Admin accounts loaded from admins.txt |
hashPasajeros | HashTable<Passenger> | Parallel hash keyed by DNI — O(1) passenger lookup |
hashConductores | HashTable<Driver> | Parallel hash keyed by DNI — O(1) driver lookup |
vehicleTree | BinarySearchTree* | BST for vehicle search by plate |
Passenger Methods
Validates that the DNI is exactly 8 numeric digits, checks that the DNI does not already exist in either role, creates a
Passenger with an auto-generated PAS-XXXX ID, appends it to passengerList, and inserts it into hashPasajeros.Uses
hashPasajeros.buscar() for O(1) lookup, then delegates to Passenger::login() to compare credentials.Hash lookup — returns the matching
Passenger, or an empty default-constructed Passenger if not found.Increments
totalTrips and adds precio to totalSpent on the passenger, then updates both the linked list and the hash table.Updates name and password in the linked list, the hash table, and persists to file.
Recalculates the passenger rating using a weighted average and updates both in-memory structures plus the file.
Driver Methods
Validates the DNI, creates a
Driver with an auto-generated DRV-XXXX ID and the provided Vehicle, appends to driverList, inserts into hashConductores, and rebuilds vehicleTree.Uses
hashConductores.buscar() for O(1) lookup, then calls Driver::login().Hash lookup — returns the matching
Driver, or an empty Driver if not found.Calls
Driver::acceptRide(precio) — sets isAvailable = false, increments totalTrips, adds to totalEarnings. Updates list, hash, and file.Calls
Driver::finishRide() — sets isAvailable = true. Updates list, hash, and file.Calls
Driver::updateRating() (weighted average) and persists the change.Linear scan of
driverList — returns the DNI of the first driver where getIsAvailable() is true, or "" if none are free.Uses
LinkedList::filter with a lambda to return a new heap-allocated list containing only available drivers. The caller owns the returned pointer and is responsible for deleting it.Recursive method that counts how many drivers in
driverList have getIsAvailable() == true. Base case: indice >= driverList->getSize() returns 0. Pass 0 as the starting index.Inserts all drivers into a temporary
AVLTree keyed by rating and returns those whose rating falls within [ratingMin, ratingMax].Admin Methods
Linear search of
adminList by username, then compares the stored password directly.Admin accounts are seeded automatically at startup by
FileManager::generarAdminsTXT(). The system ships with four fixed admin accounts (Yeremy, Salvador, Melissa, Edson) plus randomly generated test accounts.Sorting Methods
| Method | Algorithm | Sorts By |
|---|---|---|
sortDriversByRating() | Shell Sort | Driver rating, highest first |
sortDriversByRatingHeapSort() | HeapSort | Driver rating, highest first |
sortUsersBySpent() | Insertion Sort | Passenger totalSpent, highest first |
sortPassengersById() | Insertion Sort | Passenger ID number, ascending |
sortDriversById() | Insertion Sort | Driver ID number, ascending |
Heap-Based Extremes
Builds a max-heap over the driver array and peeks at the root — O(n) to find the highest-rated driver.
Builds a min-heap — O(n) to find the lowest-rated driver.
Builds a max-heap over passengers ordered by
totalSpent — O(n) to find the highest-spending passenger.Builds a min-heap over passengers ordered by
totalSpent — O(n) to find the lowest-spending passenger.Persistence Methods
| Method | Description |
|---|---|
saveAll() | Sorts both lists and writes passengers, drivers, and the binary password file |
savePassengers() | Sorts then writes only the passenger file |
saveDrivers() | Sorts then writes only the driver file |
saveAdmins() | Sorts then writes only the admin file |
reloadPassengers() | Re-reads passengers.txt, sanitises, and rebuilds hash |
reloadDrivers() | Re-reads drivers.txt, sanitises, rebuilds hash and vehicle tree |
reloadAdmins() | Re-reads admins.txt and sanitises IDs |
readPasswordsBinary() | Returns vector<FileManager::PasswordPreview> from passwords.bin |
Usage Example
DNI Validation
ThevalidateDni method uses an internal lambda to enforce the 8-digit numeric rule: