Zip and Skip Tries
Loading...
Searching...
No Matches
Functions
data.cpp File Reference

Implements utilities for saving performance data and formatting time. More...

#include "data.hpp"
#include <fstream>
#include <string>
#include <iostream>
Include dependency graph for data.cpp:

Go to the source code of this file.

Functions

void save_search_data (const std::string &method, size_t n, size_t m, size_t l, size_t num_nanoseconds, size_t num_repetitions, size_t min_par_compare, bool is_genetic)
 Saves search performance data to a CSV file.
 
void save_construction_data (const std::string &method, size_t n, size_t m, size_t l, size_t num_nanoseconds, size_t num_repetitions, size_t min_par_compare, bool is_genetic)
 Saves construction performance data to a CSV file.
 
void save_removal_data (const std::string &method, size_t n, size_t m, size_t l, size_t num_nanoseconds, size_t num_repetitions, size_t min_par_compare, bool is_genetic)
 Saves removal performance data to a CSV file.
 
std::string get_hostname ()
 Retrieves the hostname of the machine executing the code.
 
std::string pretty_print (size_t nanoseconds)
 Converts a duration in nanoseconds to a human-readable string format.
 

Detailed Description

Implements utilities for saving performance data and formatting time.

Definition in file data.cpp.

Function Documentation

◆ get_hostname()

std::string get_hostname ( )

Retrieves the hostname of the machine executing the code.

Implemented by reading from /proc/sys/kernel/hostname on Linux systems.

Returns
std::string The hostname.

Definition at line 50 of file data.cpp.

51{
52 std::string hostname;
53 // Attempt to open the hostname file provided by the kernel (Linux-specific).
54 std::ifstream file("/proc/sys/kernel/hostname");
55 if (file.is_open()) // Check if the file was successfully opened
56 {
57 // Read the entire line (hostname) from the file.
58 std::getline(file, hostname);
59 // File is automatically closed when 'file' goes out of scope.
60 }
61 // Return the retrieved hostname (or an empty string if reading failed).
62 return hostname;
63}
T * alloc_to_device(size_t size)
Allocates memory on the CUDA device.

◆ pretty_print()

std::string pretty_print ( size_t  nanoseconds)

Converts a duration in nanoseconds to a human-readable string format.

Formats the time into hours (h), minutes (m), seconds (s), and milliseconds (ms) as appropriate.

Parameters
nanosecondsThe duration in nanoseconds.
Returns
std::string A formatted string representing the duration (e.g., "1m 30s 500ms", "120ms").

Definition at line 65 of file data.cpp.

66{
67 size_t milliseconds = nanoseconds / 1e6;
68 size_t seconds = nanoseconds / 1e9;
69 size_t minutes = seconds / 60;
70 size_t hours = minutes / 60;
71
72 // Build the output string based on the largest significant unit.
73 if (hours > 0)
74 {
75 // Format as h, m, s, ms
76 return std::to_string(hours) + "h " + std::to_string(minutes % 60) + "m " + std::to_string(seconds % 60) + "s " + std::to_string(milliseconds % 1000) + "ms";
77 }
78 else if (minutes > 0)
79 {
80 // Format as m, s, ms
81 return std::to_string(minutes) + "m " + std::to_string(seconds % 60) + "s " + std::to_string(milliseconds % 1000) + "ms";
82 }
83 else if (seconds > 0)
84 {
85 // Format as s, ms
86 return std::to_string(seconds) + "s " + std::to_string(milliseconds % 1000) + "ms";
87 }
88 else // Only milliseconds or less
89 {
90 // Format as ms
91 return std::to_string(milliseconds) + "ms";
92 }
93}

◆ save_construction_data()

void save_construction_data ( const std::string method,
size_t  n,
size_t  m,
size_t  l,
size_t  num_nanoseconds,
size_t  num_repetitions = 1,
size_t  min_par_compare = 0,
bool  is_genetic = false 
)

Saves construction performance data to a CSV file.

Appends a record to a CSV file named based on the hostname, method, and data type. The file stores parameters and timing results for data structure construction operations.

Parameters
methodA string identifying the construction method or data structure used (e.g., "SkipTrie", "ParallelZipTrie").
nThe number of elements inserted during the construction.
mThe characteristic length of the elements being inserted (e.g., average or fixed string length).
lA parameter potentially representing the average LCP length of the inserted data, or another characteristic.
num_nanosecondsThe total time taken for the construction operation(s), in nanoseconds.
num_repetitionsThe number of times the construction operation was repeated or batched. Defaults to 1.
min_par_compareA parameter potentially related to parallel comparison thresholds used during construction. Defaults to 0.
is_geneticFlag indicating whether the data pertains to genetic (true) or synthetic (false) datasets. Defaults to false.

Definition at line 24 of file data.cpp.

25{
26 // Construct the full path and filename for the CSV data file.
28 std::string filename = PREFIX + method + CSV_EXTENSION;
29
30 // Open the file in append mode. Creates the file if it doesn't exist.
31 std::ofstream file(filename, std::ios::app);
32 // Write the data as a single line, comma-separated.
33 file << n << "," << m << "," << l << "," << num_nanoseconds << "," << num_repetitions << "," << min_par_compare << std::endl;
34 // File is automatically closed when 'file' goes out of scope.
35}
static const std::string CSV_EXTENSION
Standard file extension for Comma Separated Value files.
Definition data.hpp:29
static const std::string CONSTRUCTION_DATA_FILENAME
Base filename prefix for construction performance data files.
Definition data.hpp:25
static const std::string HOSTNAME
Constant string storing the hostname, retrieved once at program startup.
Definition data.hpp:99
const std::string & get_data_directory(bool is_genetic=false)
Gets the appropriate data directory path based on the data type.
Definition data.hpp:36

◆ save_removal_data()

void save_removal_data ( const std::string method,
size_t  n,
size_t  m,
size_t  l,
size_t  num_nanoseconds,
size_t  num_repetitions = 1,
size_t  min_par_compare = 0,
bool  is_genetic = false 
)

Saves removal performance data to a CSV file.

Appends a record to a CSV file named based on the hostname, method, and data type. The file stores parameters and timing results for data structure removal operations.

Parameters
methodA string identifying the removal method or data structure used (e.g., "SkipTrie", "ParallelZipTrie").
nThe number of elements present before removal or the number of elements removed.
mThe characteristic length of the elements being removed (e.g., average or fixed string length).
lA parameter potentially representing the LCP or other characteristic related to the removed elements.
num_nanosecondsThe total time taken for the removal operation(s), in nanoseconds.
num_repetitionsThe number of times the removal operation was repeated or batched. Defaults to 1.
min_par_compareA parameter potentially related to parallel comparison thresholds used during removal. Defaults to 0.
is_geneticFlag indicating whether the data pertains to genetic (true) or synthetic (false) datasets. Defaults to false.

Definition at line 37 of file data.cpp.

38{
39 // Construct the full path and filename for the CSV data file.
41 std::string filename = PREFIX + method + CSV_EXTENSION;
42
43 // Open the file in append mode. Creates the file if it doesn't exist.
44 std::ofstream file(filename, std::ios::app);
45 // Write the data as a single line, comma-separated.
46 file << n << "," << m << "," << l << "," << num_nanoseconds << "," << num_repetitions << "," << min_par_compare << std::endl;
47 // File is automatically closed when 'file' goes out of scope.
48}
static const std::string REMOVAL_DATA_FILENAME
Base filename prefix for removal performance data files.
Definition data.hpp:27

◆ save_search_data()

void save_search_data ( const std::string method,
size_t  n,
size_t  m,
size_t  l,
size_t  num_nanoseconds,
size_t  num_repetitions = 1,
size_t  min_par_compare = 0,
bool  is_genetic = false 
)

Saves search performance data to a CSV file.

Appends a record to a CSV file named based on the hostname, method, and data type. The file stores parameters and timing results for search operations.

Parameters
methodA string identifying the search method or data structure used (e.g., "SkipTrie", "ParallelZipTrie").
nThe number of elements in the data structure when the search was performed.
mThe length of the search key (e.g., number of characters or bits).
lThe Longest Common Prefix (LCP) length between the search key and its path/result in the structure.
num_nanosecondsThe total time taken for the search operation(s), in nanoseconds.
num_repetitionsThe number of times the search operation was repeated to get the total time. Defaults to 1.
min_par_compareA parameter potentially related to parallel comparison thresholds (specific meaning depends on context). Defaults to 0.
is_geneticFlag indicating whether the data pertains to genetic (true) or synthetic (false) datasets. Defaults to false.

Definition at line 11 of file data.cpp.

12{
13 // Construct the full path and filename for the CSV data file.
15 std::string filename = PREFIX + method + CSV_EXTENSION;
16
17 // Open the file in append mode. Creates the file if it doesn't exist.
18 std::ofstream file(filename, std::ios::app);
19 // Write the data as a single line, comma-separated.
20 file << n << "," << m << "," << l << "," << num_nanoseconds << "," << num_repetitions << "," << min_par_compare << std::endl;
21 // File is automatically closed when 'file' goes out of scope.
22}
static const std::string SEARCH_DATA_FILENAME
Base filename prefix for search performance data files.
Definition data.hpp:23