base: Add static assert to trie

Trie is based on the condition that they key is an integral. As so,
add a static_assert to guarantee that. Also, added some general info
about tries to the class.

Change-Id: Idc18f6a685db8047cd44b791f427666d3dd2d187
Signed-off-by: Daniel R. Carvalho <odanrc@yahoo.com.br>
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/26784
Reviewed-by: Gabe Black <gabeblack@google.com>
Maintainer: Bobby R. Bruce <bbruce@ucdavis.edu>
Tested-by: kokoro <noreply+kokoro@google.com>
This commit is contained in:
Daniel R. Carvalho
2020-03-10 09:58:07 +01:00
committed by Daniel Carvalho
parent 6bc9572914
commit d8e7d6bcb9

View File

@@ -31,16 +31,27 @@
#include <cassert>
#include <iostream>
#include <type_traits>
#include "base/cprintf.hh"
#include "base/logging.hh"
#include "base/types.hh"
// Key has to be an integral type.
/**
* A trie is a tree-based data structure used for data retrieval. It uses
* bits masked from the msb of the key to to determine a value's location,
* so its lookups have their worst case time dictated by the key's size.
*
* @tparam Key Type of the key of the tree nodes. Must be an integral type.
* @tparam Value Type of the values associated to the keys.
*/
template <class Key, class Value>
class Trie
{
protected:
static_assert(std::is_integral<Key>::value,
"Key has to be an integral type");
struct Node
{
Key key;