Skip to content

Commit 38956ba

Browse files
juliaschroederjengelh
authored andcommitted
ab_tree: move minid/GUID conversion
1 parent 3a60c74 commit 38956ba

File tree

2 files changed

+14
-31
lines changed

2 files changed

+14
-31
lines changed

include/gromox/ab_tree.hpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ struct minid
105105
static constexpr uint32_t RESOLVED = 0x0000002;
106106

107107
constexpr minid(uint32_t i = 0) : id(i) {}
108+
constexpr explicit minid(const GUID &guid) : id(guid.time_low) {}
108109
/**
109110
* @brief Construct minid from type and ID
110111
*
@@ -113,6 +114,7 @@ struct minid
113114
*/
114115
constexpr minid(Type t, uint32_t v) : id((uint32_t(t) << TYPEOFFSET) | ((v + 0x10) & VALMASK)) {}
115116
constexpr operator uint32_t() const { return id; }
117+
constexpr explicit operator GUID() const { return GUID{id, 0, 0, {0, 0}, {0, 0, 0, 0, 0, 0}}; }
116118

117119
constexpr Type type() const { return Type(id >> TYPEOFFSET); } ///< Extract type from minid
118120
constexpr uint32_t value() const { return (id & VALMASK) - 0x10; } ///< Extract object ID from minid
@@ -217,6 +219,7 @@ class ab_base
217219
const sql_user *fetch_user(minid) const;
218220
uint32_t get_leaves_num(minid) const;
219221
inline const GUID &guid() const { return m_guid; }
222+
size_t hidden() const;
220223
uint32_t hidden(minid) const;
221224
ec_error_t mdbdn(minid, std::string &) const;
222225
bool mlist_info(minid, std::string *, std::string *, int *) const;
@@ -235,8 +238,6 @@ class ab_base
235238
inline iterator uend() const { return iterator(this, m_users.cend()); } ///< Iterator to end of user list
236239
iterator find(minid) const;
237240

238-
static minid from_guid(const GUID &);
239-
static GUID guid(minid);
240241
static display_type dtypx_to_etyp(display_type);
241242

242243
private:
@@ -357,7 +358,7 @@ struct ab_node
357358

358359
#undef WRAP
359360

360-
inline GUID guid() const { return ab_base::guid(mid); }
361+
inline GUID guid() const { return GUID(mid); }
361362
inline bool valid() const { return base && base->exists(mid); }
362363

363364
using iterator = decltype(ab_domain::userref)::const_iterator;

lib/ab_tree.cpp

Lines changed: 10 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -489,21 +489,6 @@ bool ab_base::fetch_props(minid mid, const PROPTAG_ARRAY &tags, std::unordered_m
489489
return true;
490490
}
491491

492-
/**
493-
* @brief Extract minid from node GUID
494-
*
495-
* No checks are performed whether the resulting minid is valid.
496-
* Use exists() to check whether the minid is usable.
497-
*
498-
* @param guid GUID of the node
499-
*
500-
* @return Node minid
501-
*/
502-
minid ab_base::from_guid(const GUID &guid)
503-
{
504-
return guid.time_low;
505-
}
506-
507492
/**
508493
* @brief Get total number of children of the node
509494
*
@@ -520,30 +505,27 @@ uint32_t ab_base::get_leaves_num(minid mid) const
520505
}
521506

522507
/**
523-
* @brief Generate node GUID
508+
* @brief Get the number of direct child nodes
524509
*
525510
* @param mid Mid of the node
526511
*
527-
* @return Node GUID
512+
* @return Number of users of a domain node or 0 for user nodes
528513
*/
529-
GUID ab_base::guid(minid mid)
514+
size_t ab_base::children(minid mid) const
530515
{
531-
GUID g{};
532-
g.time_low = mid;
533-
return g;
516+
const ab_domain *domain = fetch_domain(mid);
517+
return domain ? domain->userref.size() : 0;
534518
}
535519

536520
/**
537-
* @brief Get the number of direct child nodes
521+
* @brief Count number of users hidden from GAL
538522
*
539-
* @param mid Mid of the node
540-
*
541-
* @return Number of users of a domain node or 0 for user nodes
523+
* @return Number of users with AB_HIDE_FROM_GAL flag set
542524
*/
543-
size_t ab_base::children(minid mid) const
525+
size_t ab_base::hidden() const
544526
{
545-
const ab_domain *domain = fetch_domain(mid);
546-
return domain ? domain->userref.size() : 0;
527+
return uint32_t(std::count_if(m_users.begin(), m_users.end(),
528+
[](const sql_user& u) {return u.hidden & AB_HIDE_FROM_GAL;}));
547529
}
548530

549531
/**

0 commit comments

Comments
 (0)