mirror of
https://github.com/microsoft/terminal.git
synced 2025-12-19 18:11:39 -05:00
wyhash was chosen based on the results found in `smhasher`, were it proved itself as an algorithm with little flaws and fairly high output quality. While I have a personal preference for xxhash (XXH3 specifically), wyhash is a better fit for this project as its source code is multiple magnitudes smaller, simplifying the review and integration into the header-only `hash.h` file. For use with hashmaps the hash quality doesn't actually matter much for optimal performance and instead the binary size usually matters more. But even in that scenario wyhash is fairly close to FNV1a (aka "FNV64"). The result is that this new hash algorithm will only have little impact on hashmap performance if used over the standard FNV1a as used in the STL, while simultaneously offering a vastly better hash quality. This partially solves #13124. ## Validation Steps Performed * Added test cases ✅
66 lines
1.5 KiB
C++
66 lines
1.5 KiB
C++
/*++
|
|
Copyright (c) Microsoft Corporation
|
|
Licensed under the MIT license.
|
|
|
|
Module Name:
|
|
- UnicodeStorage.hpp
|
|
|
|
Abstract:
|
|
- dynamic storage location for glyphs that can't normally fit in the output buffer
|
|
|
|
Author(s):
|
|
- Austin Diviness (AustDi) 02-May-2018
|
|
--*/
|
|
|
|
#pragma once
|
|
|
|
#include <unordered_map>
|
|
#include <vector>
|
|
|
|
#include <til/hash.h>
|
|
|
|
// std::unordered_map needs help to know how to hash a til::point
|
|
namespace std
|
|
{
|
|
template<>
|
|
struct hash<til::point>
|
|
{
|
|
// Routine Description:
|
|
// - hashes a coord. coord will be hashed by storing the x and y values consecutively in the lower
|
|
// bits of a size_t.
|
|
// Arguments:
|
|
// - coord - the coord to hash
|
|
// Return Value:
|
|
// - the hashed coord
|
|
size_t operator()(const til::point coord) const noexcept
|
|
{
|
|
return til::hash(coord);
|
|
}
|
|
};
|
|
}
|
|
|
|
class UnicodeStorage final
|
|
{
|
|
public:
|
|
using key_type = typename til::point;
|
|
using mapped_type = typename std::vector<wchar_t>;
|
|
|
|
UnicodeStorage() noexcept;
|
|
|
|
const mapped_type& GetText(const key_type key) const;
|
|
|
|
void StoreGlyph(const key_type key, const mapped_type& glyph);
|
|
|
|
void Erase(const key_type key) noexcept;
|
|
|
|
void Remap(const std::unordered_map<til::CoordType, til::CoordType>& rowMap, const std::optional<til::CoordType> width);
|
|
|
|
private:
|
|
std::unordered_map<key_type, mapped_type> _map;
|
|
|
|
#ifdef UNIT_TESTING
|
|
friend class UnicodeStorageTests;
|
|
friend class TextBufferTests;
|
|
#endif
|
|
};
|