ONE - On-device Neural Engine
Loading...
Searching...
No Matches
flexbuffers::Map Class Reference

#include <flexbuffers.h>

Collaboration diagram for flexbuffers::Map:

Public Member Functions

 Map (const uint8_t *data, uint8_t byte_width)
 
Reference operator[] (const char *key) const
 
Reference operator[] (const std::string &key) const
 
Vector Values () const
 
TypedVector Keys () const
 
bool IsTheEmptyMap () const
 
- Public Member Functions inherited from flexbuffers::Vector
 Vector (const uint8_t *data, uint8_t byte_width)
 
Reference operator[] (size_t i) const
 
bool IsTheEmptyVector () const
 
- Public Member Functions inherited from flexbuffers::Sized
 Sized (const uint8_t *data, uint8_t byte_width)
 
 Sized (const uint8_t *data, uint8_t byte_width, size_t sz)
 
size_t size () const
 
size_t read_size () const
 
- Public Member Functions inherited from flexbuffers::Object
 Object (const uint8_t *data, uint8_t byte_width)
 

Static Public Member Functions

static Map EmptyMap ()
 
- Static Public Member Functions inherited from flexbuffers::Vector
static Vector EmptyVector ()
 

Additional Inherited Members

- Protected Attributes inherited from flexbuffers::Sized
size_t size_
 
- Protected Attributes inherited from flexbuffers::Object
const uint8_t * data_
 
uint8_t byte_width_
 

Detailed Description

Definition at line 347 of file flexbuffers.h.

Constructor & Destructor Documentation

◆ Map()

flexbuffers::Map::Map ( const uint8_t *  data,
uint8_t  byte_width 
)
inline

Definition at line 350 of file flexbuffers.h.

350: Vector(data, byte_width) {}

Member Function Documentation

◆ EmptyMap()

static Map flexbuffers::Map::EmptyMap ( )
inlinestatic

Definition at line 366 of file flexbuffers.h.

367 {
368 static const uint8_t empty_map[] = {
369 0 /*keys_len*/, 0 /*keys_offset*/, 1 /*keys_width*/, 0 /*len*/
370 };
371 return Map(empty_map + 4, 1);
372 }
Map(const uint8_t *data, uint8_t byte_width)

Referenced by flexbuffers::Reference::AsMap(), and IsTheEmptyMap().

◆ IsTheEmptyMap()

bool flexbuffers::Map::IsTheEmptyMap ( ) const
inline

Definition at line 374 of file flexbuffers.h.

374{ return data_ == EmptyMap().data_; }
static Map EmptyMap()
const uint8_t * data_

References flexbuffers::Object::data_, and EmptyMap().

◆ Keys()

TypedVector flexbuffers::Map::Keys ( ) const
inline

Definition at line 357 of file flexbuffers.h.

358 {
359 const size_t num_prefixed_fields = 3;
360 auto keys_offset = data_ - byte_width_ * num_prefixed_fields;
361 return TypedVector(Indirect(keys_offset, byte_width_),
362 static_cast<uint8_t>(ReadUInt64(keys_offset + byte_width_, byte_width_)),
363 FBT_KEY);
364 }
uint64_t ReadUInt64(const uint8_t *data, uint8_t byte_width)
const uint8_t * Indirect(const uint8_t *offset, uint8_t byte_width)

References flexbuffers::Object::byte_width_, flexbuffers::Object::data_, flexbuffers::FBT_KEY, flexbuffers::Indirect(), and flexbuffers::ReadUInt64().

Referenced by operator[](), circledump::CustomOpPrinter::options(), and tfldump::CustomOpPrinter::options().

◆ operator[]() [1/2]

Reference flexbuffers::Map::operator[] ( const char *  key) const
inline

Definition at line 977 of file flexbuffers.h.

978{
979 auto keys = Keys();
980 // We can't pass keys.byte_width_ to the comparison function, so we have
981 // to pick the right one ahead of time.
982 int (*comp)(const void *, const void *) = nullptr;
983 switch (keys.byte_width_)
984 {
985 case 1:
986 comp = KeyCompare<uint8_t>;
987 break;
988 case 2:
989 comp = KeyCompare<uint16_t>;
990 break;
991 case 4:
992 comp = KeyCompare<uint32_t>;
993 break;
994 case 8:
995 comp = KeyCompare<uint64_t>;
996 break;
997 }
998 auto res = std::bsearch(key, keys.data_, keys.size(), keys.byte_width_, comp);
999 if (!res)
1000 return Reference(nullptr, 1, NullPackedType());
1001 auto i = (reinterpret_cast<uint8_t *>(res) - keys.data_) / keys.byte_width_;
1002 return (*static_cast<const Vector *>(this))[i];
1003}
TypedVector Keys() const
uint8_t NullPackedType()

References Keys(), and flexbuffers::NullPackedType().

◆ operator[]() [2/2]

Reference flexbuffers::Map::operator[] ( const std::string &  key) const
inline

Definition at line 1005 of file flexbuffers.h.

1005{ return (*this)[key.c_str()]; }

◆ Values()

Vector flexbuffers::Map::Values ( ) const
inline

Definition at line 355 of file flexbuffers.h.

355{ return Vector(data_, byte_width_); }

References flexbuffers::Object::byte_width_, and flexbuffers::Object::data_.


The documentation for this class was generated from the following file: