Skip to main content

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.

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 (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

FieldTypePurpose
passengerListLinkedList<Passenger>*Primary ordered list of all passengers
driverListLinkedList<Driver>*Primary ordered list of all drivers
adminListLinkedList<FileManager::AdminPreview>*Admin accounts loaded from admins.txt
hashPasajerosHashTable<Passenger>Parallel hash keyed by DNI — O(1) passenger lookup
hashConductoresHashTable<Driver>Parallel hash keyed by DNI — O(1) driver lookup
vehicleTreeBinarySearchTree*BST for vehicle search by plate
The constructor loads all three user types from file, sanitises any duplicate or malformed IDs, compacts the ID sequences, and then rebuilds all hash tables:
AuthManager() {
    // Load from files
    // Sanitize + sort + compact IDs
    // Rebuild hash tables
    reconstruirHashPasajeros();
    reconstruirHashConductores();
    reconstruirArbolVehiculos();
}

Passenger Methods

registerUser / registerPassenger
bool
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.
bool registerUser(string name, string dni, string password);
bool registerPassenger(string name, string dni, string password);
loginUserValid
bool
Uses hashPasajeros.buscar() for O(1) lookup, then delegates to Passenger::login() to compare credentials.
bool loginUserValid(string dni, string password);
getUserByDni
Passenger
Hash lookup — returns the matching Passenger, or an empty default-constructed Passenger if not found.
Passenger getUserByDni(string dni);
addTripToUser
void
Increments totalTrips and adds precio to totalSpent on the passenger, then updates both the linked list and the hash table.
void addTripToUser(string dni, float precio);
updatePassengerData
void
Updates name and password in the linked list, the hash table, and persists to file.
void updatePassengerData(string dni, string newName, string newPass);
updateUserRating
void
Recalculates the passenger rating using a weighted average and updates both in-memory structures plus the file.
void updateUserRating(string dni, float nuevaCalif);

Driver Methods

registerDriver
bool
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.
bool registerDriver(string name, string dni, string password, Vehicle vehicle);
loginDriverValid
bool
Uses hashConductores.buscar() for O(1) lookup, then calls Driver::login().
bool loginDriverValid(string dni, string password);
getDriverByDni
Driver
Hash lookup — returns the matching Driver, or an empty Driver if not found.
Driver getDriverByDni(string dni);
driverAcceptRide
void
Calls Driver::acceptRide(precio) — sets isAvailable = false, increments totalTrips, adds to totalEarnings. Updates list, hash, and file.
void driverAcceptRide(string dni, float precio);
driverFinishRide
void
Calls Driver::finishRide() — sets isAvailable = true. Updates list, hash, and file.
void driverFinishRide(string dni);
updateDriverRating
void
Calls Driver::updateRating() (weighted average) and persists the change.
void updateDriverRating(string dni, float nuevaCalif);
findAvailableDriver
string
Linear scan of driverList — returns the DNI of the first driver where getIsAvailable() is true, or "" if none are free.
string findAvailableDriver();
getConductoresDisponibles
LinkedList<Driver>*
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.
LinkedList<Driver>* getConductoresDisponibles();
// Internally: driverList->filter([](Driver d){ return d.getIsAvailable(); });
contarConductoresDisponibles
int
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.
int contarConductoresDisponibles(int indice);
// Example: int total = auth.contarConductoresDisponibles(0);
buscarConductoresPorRangoRating
vector<Driver>
Inserts all drivers into a temporary AVLTree keyed by rating and returns those whose rating falls within [ratingMin, ratingMax].
vector<Driver> buscarConductoresPorRangoRating(float ratingMin, float ratingMax);

Admin Methods

loginAdminValid
bool
Linear search of adminList by username, then compares the stored password directly.
bool loginAdminValid(string username, string password);
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

MethodAlgorithmSorts By
sortDriversByRating()Shell SortDriver rating, highest first
sortDriversByRatingHeapSort()HeapSortDriver rating, highest first
sortUsersBySpent()Insertion SortPassenger totalSpent, highest first
sortPassengersById()Insertion SortPassenger ID number, ascending
sortDriversById()Insertion SortDriver ID number, ascending

Heap-Based Extremes

getDriverMaxRatingHeap
Driver
Builds a max-heap over the driver array and peeks at the root — O(n) to find the highest-rated driver.
Driver getDriverMaxRatingHeap();
getDriverMinRatingHeap
Driver
Builds a min-heap — O(n) to find the lowest-rated driver.
Driver getDriverMinRatingHeap();
getPassengerMaxTotalSpentHeap
Passenger
Builds a max-heap over passengers ordered by totalSpent — O(n) to find the highest-spending passenger.
Passenger getPassengerMaxTotalSpentHeap();
getPassengerMinTotalSpentHeap
Passenger
Builds a min-heap over passengers ordered by totalSpent — O(n) to find the lowest-spending passenger.
Passenger getPassengerMinTotalSpentHeap();

Persistence Methods

MethodDescription
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

AuthManager auth;
// Constructor automatically loads and sanitises all data from files

// Register a passenger
bool ok = auth.registerUser("Carlos López", "12345678", "mypass");

// Login — O(1) via hash table
bool valid = auth.loginUserValid("12345678", "mypass");

// Get driver with highest rating using a max-heap
Driver best = auth.getDriverMaxRatingHeap();
cout << best.getName() << " - " << best.getRating() << "\n";

// Find all drivers rated between 4.0 and 5.0
vector<Driver> topDrivers = auth.buscarConductoresPorRangoRating(4.0f, 5.0f);

// Sort passengers by total spend (Insertion Sort)
auth.sortUsersBySpent();

DNI Validation

The validateDni method uses an internal lambda to enforce the 8-digit numeric rule:
bool validateDni(string dni) {
    auto esDniValido = [](string d) -> bool {
        if (d.size() != 8) return false;
        for (char c : d) if (c < '0' || c > '9') return false;
        return true;
    };
    return esDniValido(dni);
}
A DNI cannot be shared across roles. dniExistsAnyRole() checks both the passenger and driver hash tables before any registration is accepted. Attempting to register the same DNI as both passenger and driver will be rejected.

Build docs developers (and LLMs) love