<p>Richard Mudgett <strong>posted comments</strong> on this change.</p><p><a href="https://gerrit.asterisk.org/6630">View Change</a></p><p>Patch set 2:</p><p>(1 comment)</p><ul style="list-style: none; padding-left: 20px;"><li><p><a href="https://gerrit.asterisk.org/#/c/6630/2/res/res_pjsip_registrar.c">File res/res_pjsip_registrar.c:</a></p><ul style="list-style: none; padding-left: 20px;"><li><p style="margin-bottom: 4px;"><a href="https://gerrit.asterisk.org/#/c/6630/2/res/res_pjsip_registrar.c@361">Patch Set #2, Line 361:</a> </p><p><blockquote style="border-left: 1px solid #aaa; margin: 10px 0; padding: 0 10px;"><pre style="font-family: monospace,monospace; white-space: pre-wrap;">static unsigned int heap_calc_height(unsigned int num_elements)<br>{<br>   unsigned int height = 0;<br><br>    while (num_elements) {<br>                num_elements >>= 1;<br>             ++height;<br>     }<br>     return height;<br>}<br><br>static int heap_min_contact_expire_cmp(void *left, void *right)<br>{<br>       struct ast_sip_contact *left_contact = left;<br>  struct ast_sip_contact *right_contact = right;<br><br>      /* Swap left and right to get minimum expiration time remaining heap. */<br>      return ast_tvcmp(right_contact->expiration_time, left_contact->expiration_time);<br>}<br><br>static int heap_push_contact(void *obj, void *arg, int flags)<br>{<br> struct ast_sip_contact *contact = obj;<br>        struct ast_heap *contact_heap = arg;<br><br>        ast_heap_push(contact_heap, contact);<br><br>       return 0;<br>}<br><br>/*!<br> * \internal<br> * \brief Remove excess existing contacts that expire the soonest.<br> * \since 13.18.0<br> *<br> * \param contacts Container of unmodified contacts that could remove.<br> * \param to_remove Maximum number of contacts to remove.<br> *<br> * \return Nothing<br> */<br>static void remove_excess_contacts(struct ao2_container *contacts, unsigned int to_remove)<br>{<br>   struct ast_heap *contact_heap;<br><br>      ast_assert(0 < to_remove);<br><br>       /* Create a minimum contact expiration time remaining heap */<br> contact_heap = ast_heap_create(heap_calc_height(ao2_container_count(contacts)),<br>               heap_min_contact_expire_cmp, -1);<br>     if (!contact_heap) {<br>          return;<br>       }<br>     ao2_callback(contacts, OBJ_NODATA | OBJ_MULTIPLE, heap_push_contact, contact_heap);<br><br> /* Remove the excess contacts that expire the soonest */<br>      while (to_remove--) {<br>         struct ast_sip_contact *contact;<br><br>            contact = ast_heap_pop(contact_heap);<br>         if (!contact) {<br>                       break;<br>                }<br><br>           ast_sip_location_delete_contact(contact);<br>             ast_verb(3, "Removed contact '%s' from AOR '%s' due to remove_existing\n",<br>                  contact->uri, contact->aor);<br>            ast_test_suite_event_notify("AOR_CONTACT_REMOVED",<br>                  "Contact: %s\r\n"<br>                   "AOR: %s\r\n"<br>                       "UserAgent: %s",<br>                    contact->uri,<br>                      contact->aor,<br>                      contact->user_agent);<br>      }<br><br>   ast_heap_destroy(contact_heap);<br>}<br></pre></blockquote></p><p><blockquote style="border-left: 1px solid #aaa; margin: 10px 0; padding: 0 10px;">Couldn't you have done this with a more common and less expensive vector ra</blockquote></p><p style="white-space: pre-wrap; word-wrap: break-word;">The heap is implemented as a vector (i.e. array).  It just doesn't use the vector macros.  I don't need a sorted array of contacts by expiration time.  I just need to remove enough next to expire contacts to fit in the max_contacts limit.  A priority heap fits this criteria and is less expensive than a sort.</p><p style="white-space: pre-wrap; word-wrap: break-word;">Were you thinking of an insertion sort implementation to find the needed contacts to remove?</p></li></ul></li></ul><p>To view, visit <a href="https://gerrit.asterisk.org/6630">change 6630</a>. To unsubscribe, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/6630"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 13 </div>
<div style="display:none"> Gerrit-MessageType: comment </div>
<div style="display:none"> Gerrit-Change-Id: I64c107a10b70db1697d17136051ae6bf22b5314b </div>
<div style="display:none"> Gerrit-Change-Number: 6630 </div>
<div style="display:none"> Gerrit-PatchSet: 2 </div>
<div style="display:none"> Gerrit-Owner: Richard Mudgett <rmudgett@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Jenkins2 </div>
<div style="display:none"> Gerrit-Reviewer: Joshua Colp <jcolp@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Richard Mudgett <rmudgett@digium.com> </div>
<div style="display:none"> Gerrit-Comment-Date: Fri, 06 Oct 2017 14:54:14 +0000 </div>
<div style="display:none"> Gerrit-HasComments: Yes </div>