AppLayerLabs / bdk-cpp

MIT License
7 stars 12 forks source link

53 implement safecontainers for arrays and vectors #59

Closed itamarcps closed 1 year ago

itamarcps commented 1 year ago

In this Pull Request, we are introducing the SafeVector and SafeArray classes that extend our Safe Type Wrappers.

These wrappers use an std::map as a temporary storage medium for modifications, providing a more efficient memory usage model by eliminating the need for a full vector copy or initializing a complete vector of nullptrs. We opted for std::map over std::unordered_map due to its inherent ordering, ensuring safer and more efficient access to indices within the vector's current size.

This unique design allows ordered iteration over newly accessed and previously accessed keys, which is crucial for committing changes. For example, when accessing a vector of size 10 at indices 3, 5, 7, 10, 11, 12, and 13, our implementation enables sequential iteration over those exact indices upon committing.

Importantly, attempts to access elements outside the vector's bounds will result in an exception, bolstering the safety features of these classes.

The classes can be parameterized with any type T, referring to the type of the vector elements. Both classes were built following the principles outlined in the SafeBase class.

The addition of SafeVector and SafeArray further enhances our library's ability to handle data safely and efficiently, a significant step towards robust and reliable code.