libycxx was written by AI agents whose models were trained on public code that likely includes these libraries, whose licences carry obligations; this analysis is the evidence of how close libycxx is to them. Why this exists.
Similarity analysis · tuning constants and design choices
Tuning constants and design choices
Decisions an implementation makes that the standard leaves open: algorithm choices, cutoffs, growth factors and representations. Where libycxx's choice coincides with one library's arbitrary choice, that is a fingerprint; where the choice is forced or is a published algorithm's, it is not.
The cells of the other three libraries are read from the pinned sources at build time by the extractors in tools/similarity/lib/tuning.py, at the locations pinned in tuning-pins.json; a cell the extractor cannot read says so. The libycxx column, the row labels and the notes are committed in docs/similarity/tuning.toml. Source lines quoted here: libstdc++: GNU GPL v3 with the GCC Runtime Library Exception (libiberty's demangler: GPL v2 or later with a linking exception, as stated in the file); libc++: Apache License 2.0 with LLVM Exceptions; MSVC STL: Apache License 2.0 with LLVM Exceptions.
| Decision | libycxx | libstdc++ | libc++ | MSVC STL | Forced or arbitrary |
|---|---|---|---|---|---|
| std::sort algorithm | pattern-defeating quicksort (O. R. L. Peters) with branchless block partitioning; heapsort fallback | introsort (3) include/bits/stl_algo.h | introsort (8), ninther (5), median of three (4), pdqsort (2), block partitioning (2), heapsort fallback (1) libcxx/include/__algorithm/sort.h | median of three (2), ninther (2), heapsort fallback (2) stl/inc/algorithm | published algorithm Introsort and its descendants are published algorithms; the cell lists the algorithm names each source mentions. |
| sort: insertion-sort cutoff | 24 elements (pdqsort's published value); 16 in the other sorting paths | 16enum { _S_threshold = 16 };include/bits/stl_algo.h 1807–1807 | 24_LIBCPP_CONSTEXPR difference_type __limit = 24; libcxx/include/__algorithm/sort.h 726–726 | 32_INLINE_VAR constexpr int _ISORT_MAX = 32; // maximum size for insertion sort stl/inc/algorithm 596–596 | published / conventional pdqsort's reference implementation fixes this value; the smaller cutoff is the classic HP STL value. |
| sort: Tukey ninther above | 128 elements (pdqsort's published value) | not determined no location is pinned: the reviewer found no such constant or choice | 128_LIBCPP_CONSTEXPR difference_type __ninther_threshold = 128; libcxx/include/__algorithm/sort.h 728–728 | 40if (40 < _Count) { // Tukey's nintherstl/inc/algorithm 8990–8990 | published From the pdqsort reference implementation. |
| sort: partition block | 64 elements (pdqsort's published value) | not determined no location is pinned: the reviewer found no such constant or choice | enum { __block_size = sizeof(uint64_t) * 8 };libcxx/include/__algorithm/sort.h 61–61 | not determined no location is pinned: the reviewer found no such constant or choice | published From BlockQuicksort and the pdqsort reference implementation. |
| stable_sort: small-range cutoff | 16 elements, then a top-down buffered merge; integers above 512 elements go to an LSD radix sort | 7enum { _S_chunk_size = 7 };include/bits/stl_algo.h 2675–2675 | struct __stable_sort_switch {
static const unsigned value = 128 * is_trivially_copy_assignable<_Tp>::value;
};libcxx/include/__algorithm/stable_sort.h 196–198 | 32_INLINE_VAR constexpr int _ISORT_MAX = 32; // maximum size for insertion sort stl/inc/algorithm 596–596 | arbitrary Any small cutoff works; the radix path is finding F05. |
| Temporary buffer when allocation fails | halves the request until an allocation succeeds; in-place rotation algorithms without a buffer | halves the request until an allocation succeedstemplate<typename _Tp>
_GLIBCXX17_DEPRECATED
pair<_Tp*, ptrdiff_t>
get_temporary_buffer(ptrdiff_t __len) _GLIBCXX_NOEXCEPT
{
const ptrdiff_t __max =
__gnu_cxx::__numeric_traits<ptrdiff_t>::__max / sizeof(_Tp);
if (__len > __max)
__len = __max;
while (__len > 0)
{
if (_Tp* __tmp = __detail::__get_temporary_buffer<_Tp>(__len))
return pair<_Tp*, ptrdiff_t>(__tmp, __len);
__len = __len == 1 ? 0 : ((__len + 1) / 2);
}
return pair<_Tp*, ptrdiff_t>();
}
/**
* @brief The companion to get_temporary_buffer().include/bits/stl_tempbuf.h 140–160 | halves the request until an allocation succeeds// Since aligned operator new is unavailable, constructs an empty buffer rather than one with invalid alignment.
return __unique_buffer_type();
}
__ptr = static_cast<_Tp*>(::operator new(__count * sizeof(_Tp), nothrow));
#endif
if (__ptr) {
break;
}
__count /= 2;
}
return __unique_buffer_type(__ptr, __deleter_type(__count));
}libcxx/include/__memory/unique_temporary_buffer.h 75–90 | halves the request until an allocation succeedspair<_Ty*, ptrdiff_t> _Get_temporary_buffer(ptrdiff_t _Count) noexcept {
if (static_cast<size_t>(_Count) <= static_cast<size_t>(-1) / sizeof(_Ty)) {
for (; 0 < _Count; _Count /= 2) {
const auto _Size = static_cast<size_t>(_Count) * sizeof(_Ty);
void* _Pbuf;
#ifdef __cpp_aligned_new
if constexpr (alignof(_Ty) > __STDCPP_DEFAULT_NEW_ALIGNMENT__) {
_Pbuf = ::operator new(_Size, align_val_t{alignof(_Ty)}, nothrow);
} else
#endif // defined(__cpp_aligned_new)
{
_Pbuf = ::operator new(_Size, nothrstl/inc/xmemory 1593–1610 | common practice Halving on failure is the long-standing practice of get_temporary_buffer, which the standard used to specify. |
| vector growth factor | 2× (doubles the capacity) | 2× (adds the current size)_M_check_len(size_type __n, const char* __s) const
{
if (max_size() - size() < __n)
__throw_length_error(__N(__s));
const size_type __len = size() + (std::max)(size(), __n);
return (__len < size() || __len > max_size()) ? max_size() : __len;
}include/bits/stl_vector.h 2192–2200 | 2× (doubles the capacity)vector<_Tp, _Allocator>::__recommend(size_type __new_size) const {
const size_type __ms = max_size();
if (__new_size > __ms)
this->__throw_length_error();
const size_type __cap = capacity();
if (__cap >= __ms / 2)
return __ms;
return std::max<size_type>(2 * __cap, __new_size);
}libcxx/include/__vector/vector.h 863–871 | 1.5× (adds half the capacity)_CONSTEXPR20 size_type _Calculate_growth(const size_type _Newsize) const {
// given _Oldcapacity and _Newsize, calculate geometric growth
const size_type _Oldcapacity = capacity();
const auto _Max = max_size();
if (_Oldcapacity > _Max - _Oldcapacity / 2) {
return _Max; // geometric growth would overflow
}
const size_type _Geometric = _Oldcapacity + _Oldcapacity / 2;
if (_Geometric < _Newsize) {
return _Newsize; // geometric growth would be insufficient
}stl/inc/vector 2014–2028 | arbitrary, common Doubling and 1.5× are both widespread choices; the standard requires only amortised constant time. |
| deque block size | about 1 KiB per block, a power of two, at least 16 elements | #define _GLIBCXX_DEQUE_BUF_SIZE 512
#endif
_GLIBCXX_CONSTEXPR inline size_t
__deque_buf_size(size_t __size)
{ return (__size < _GLIBCXX_DEQUE_BUF_SIZE
? size_t(_GLIBCXX_DEQUE_BUF_SIZE / __size) : size_t(1)); }include/bits/stl_deque.h 95–101 | struct __deque_block_size {
static const _DiffType value = sizeof(_ValueType) < 256 ? 4096 / sizeof(_ValueType) : 16;
};libcxx/include/deque 268–270 | static constexpr int _Block_size = _Bytes <= 1 ? 16
: _Bytes <= 2 ? 8
: _Bytes <= 4 ? 4
: _Bytes <= 8 ? 2
: 1; // elements per block (a power of 2)stl/inc/deque 550–554 | arbitrary Each library picks its own size; libycxx's rule is its own. |
| basic_string inline capacity | 16 bytes of characters, so 15 chars | enum { _S_local_capacity = 15 / sizeof(_CharT) };include/bits/basic_string.h 217–217 | enum { __min_cap = (sizeof(__long) - 1) / sizeof(value_type) > 2 ? (sizeof(__long) - 1) / sizeof(value_type) : 2 };libcxx/include/string 865–865 | static constexpr size_type _BUF_SIZE = 16 / sizeof(value_type) < 1 ? 1 : 16 / sizeof(value_type); stl/inc/xstring 424–424 | arbitrary, common A widespread size; see finding F06 for the layout. |
| basic_string layout | data pointer, size, then a union of the capacity and the inline buffer; long when the pointer is not the buffer | _Alloc_hider _M_dataplus;
size_type _M_string_length;
enum { _S_local_capacity = 15 / sizeof(_CharT) };
union
{
_CharT _M_local_buf[_S_local_capacity + 1];
size_type _M_allocated_capacity;
};include/bits/basic_string.h 214–223 | struct __long {
__long() = default;
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __long(__alloc_result __alloc, size_type __size)
: __is_long_(true), __cap_(__alloc.count / __endian_factor), __size_(__size), __data_(__alloc.ptr) {
_LIBCPP_ASSERT_INTERNAL(!__fits_in_sso(__alloc.count), "Long capacity should always be larger than the SSO");
}
struct _LIBCPP_PACKED {
size_type __is_long_ : 1;
size_type __cap_ : sizeof(size_type) * CHAR_BIT - 1;
};
size_type __size_;
pointer __data_;
};
enum { __min_cap = (sizeof(__long) - 1) / silibcxx/include/string 849–888 | union _Bxty { // storage for small buffer or pointer to larger one
// This constructor previously initialized _Ptr. Don't rely on the new behavior without
// renaming `_String_val` (and fixing the visualizer).
_CONSTEXPR20 _Bxty() noexcept : _Buf() {} // user-provided, for fancy pointers
_CONSTEXPR20 ~_Bxty() noexcept {} // user-provided, for fancy pointers
value_type _Buf[_BUF_SIZE];
pointer _Ptr;
char _Alias[_BUF_SIZE]; // TRANSITION, ABI: _Alias is preserved for binary compatibility (especially /clr)stl/inc/xstring 490–498 | arbitrary Finding F06. |
| Hash table bucket counts | zero or a power of two; Fibonacci hashing picks the bucket; no prime table | prime bucket counts: a table of 257 entries, largest 4294967291 src/shared/hashtable-aux.cc | prime bucket counts: a table of 48 entries, largest 211 libcxx/src/hash.cpp | static constexpr size_type _Min_buckets = 8; // must be a positive power of 2 stl/inc/xhash 300–300 | arbitrary Prime tables and power-of-two counts are both well known; libycxx's Fibonacci hashing is its own choice. |
| Floating-point to_chars | Schubfach (R. Giulietti) for binary32/64; Steele–White / Burger–Dybvig on big integers otherwise | Ryu (48) src/c++17/floating_to_chars.cc | Ryu (21) libcxx/src/include/to_chars_floating_point.h, libcxx/src/ryu/d2s.cpp | Ryu (25), strtod-based (4), big-integer fallback (2) stl/inc/xcharconv_ryu.h, stl/inc/charconv | published algorithm All are published algorithms; libycxx's choice differs from the one the other libraries share. |
| Floating-point from_chars | Eisel–Lemire (D. Lemire, 2021), then an exact big-integer computation | fast_float (28), strtod-based (8) src/c++17/floating_from_chars.cc | not determined none of the known algorithm names occurs in the pinned files | strtod-based (4), big-integer fallback (2), Ryu (1) stl/inc/charconv | published algorithm Published algorithms. |
| type_traits | compiler intrinsics wherever one exists, few class-template specializations measured: 222 compiler-intrinsic calls, 30 class-template specializations | 191 compiler-intrinsic calls, 263 class-template specializations | 179 compiler-intrinsic calls, 123 class-template specializations | 111 compiler-intrinsic calls, 86 class-template specializations | common practice The counts are measured over each library's type_traits area; intrinsics are the compilers' public interface. |
| tuple storage | one base per element over an index sequence (flat multiple inheritance) measured: 0 self-recursive base clauses, 2 pack-expanded base clauses | 1 self-recursive base clauses, 2 pack-expanded base clauses | 4 self-recursive base clauses, 6 pack-expanded base clauses | 2 self-recursive base clauses, 2 pack-expanded base clauses | arbitrary, published Finding F03. The counts are raw base-clause shapes in each tuple area, a weak signal: read them with the finding. |
| variant storage | recursive union with conditionally trivial special members measured: recursive union (2 definitions) | recursive union (2 definitions) | not determined no union storage that nests its own template in the area (it may be generated by a macro, which normalisation removes) | recursive union (3 definitions) | common practice The recursive union is the established technique for a constexpr variant. |
| Iterator-category dispatch | if constexpr on the category or concept; few tag overloads measured: 6 overloads on an unnamed tag parameter, 33 if-constexpr on the category | 48 overloads on an unnamed tag parameter, 42 if-constexpr on the category | 42 overloads on an unnamed tag parameter, 34 if-constexpr on the category | 5 overloads on an unnamed tag parameter, 39 if-constexpr on the category | arbitrary, common Tag-dispatch overloads are the pre-C++17 idiom, if constexpr the modern one; the counts are measured over the iterator and algorithm areas. |