<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"> <title>DTN Reference Implementation: Repository.cc Source File</title> <link href="doxygen.css" rel="stylesheet" type="text/css"> <link href="tabs.css" rel="stylesheet" type="text/css"> </head><body> <!-- Generated by Doxygen 1.5.6 --> <div class="navigation" id="top"> <div class="tabs"> <ul> <li><a href="main.html"><span>Main Page</span></a></li> <li><a href="namespaces.html"><span>Namespaces</span></a></li> <li><a href="annotated.html"><span>Classes</span></a></li> <li class="current"><a href="files.html"><span>Files</span></a></li> </ul> </div> <h1>Repository.cc</h1><a href="Repository_8cc.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span> <a name="l00002"></a>00002 <span class="comment"> * Copyright 2007 Baylor University</span> <a name="l00003"></a>00003 <span class="comment"> *</span> <a name="l00004"></a>00004 <span class="comment"> * Licensed under the Apache License, Version 2.0 (the "License");</span> <a name="l00005"></a>00005 <span class="comment"> * you may not use this file except in compliance with the License.</span> <a name="l00006"></a>00006 <span class="comment"> * You may obtain a copy of the License at</span> <a name="l00007"></a>00007 <span class="comment"> *</span> <a name="l00008"></a>00008 <span class="comment"> * http://www.apache.org/licenses/LICENSE-2.0</span> <a name="l00009"></a>00009 <span class="comment"> *</span> <a name="l00010"></a>00010 <span class="comment"> * Unless required by applicable law or agreed to in writing, software</span> <a name="l00011"></a>00011 <span class="comment"> * distributed under the License is distributed on an "AS IS" BASIS,</span> <a name="l00012"></a>00012 <span class="comment"> * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.</span> <a name="l00013"></a>00013 <span class="comment"> * See the License for the specific language governing permissions and</span> <a name="l00014"></a>00014 <span class="comment"> * limitations under the License.</span> <a name="l00015"></a>00015 <span class="comment"> */</span> <a name="l00016"></a>00016 <a name="l00017"></a>00017 <span class="preprocessor">#include "<a class="code" href="Repository_8h.html">Repository.h</a>"</span> <a name="l00018"></a>00018 <a name="l00019"></a><a class="code" href="Repository_8cc.html#275861c30b08ec652f25510a884ccd58">00019</a> <span class="preprocessor">#define LOG(_level,_args...) core_->print_log("repository", \</span> <a name="l00020"></a>00020 <span class="preprocessor"> BundleCore::_level, _args);</span> <a name="l00021"></a>00021 <span class="preprocessor"></span> <a name="l00022"></a>00022 <span class="keyword">namespace </span>prophet <a name="l00023"></a>00023 { <a name="l00024"></a>00024 <a name="l00025"></a><a class="code" href="classprophet_1_1Repository.html#856860fe7b2079d5d5a57b810c66fe58">00025</a> <a class="code" href="classprophet_1_1Repository.html#856860fe7b2079d5d5a57b810c66fe58" title="Constructor.">Repository::Repository</a>(<a class="code" href="classprophet_1_1Repository_1_1BundleCoreRep.html" title="Reduced interface into BundleCore to provide logging, drop_bundle signal, and answer...">BundleCoreRep</a>* core, <a name="l00026"></a>00026 <a class="code" href="classprophet_1_1QueueComp.html" title="Bundle queuing policy requires a sort order, which is provided by QueueComp and its...">QueueComp</a>* qc, <a name="l00027"></a>00027 <span class="keyword">const</span> <a class="code" href="classprophet_1_1BundleList.html" title="List of Prophet&#39;s Bundle facade objects.">BundleList</a>* list) <a name="l00028"></a>00028 : core_(core), comp_(NULL), current_(0) <a name="l00029"></a>00029 { <a name="l00030"></a>00030 <span class="comment">// default comparator is FIFO</span> <a name="l00031"></a>00031 <span class="keywordflow">if</span> (qc == NULL) <a name="l00032"></a>00032 { <a name="l00033"></a>00033 <a class="code" href="classprophet_1_1Repository.html#cb20665e4d1142b8238574e870459080" title="queue policy Bundle comparator">comp_</a> = <a class="code" href="structprophet_1_1QueuePolicy.html#0af83ec59196788050fff090528d61a7" title="Factory method for creating QueuePolicy comparator instance.">QueuePolicy::policy</a>(<a class="code" href="structprophet_1_1QueuePolicy.html#41e2705af81c561ed69d802afa47ed6800b0cb9c3951d7d6db33102917550f3f">QueuePolicy::FIFO</a>); <a name="l00034"></a>00034 } <a name="l00035"></a>00035 <span class="keywordflow">else</span> <a name="l00036"></a>00036 { <a name="l00037"></a>00037 <a class="code" href="classprophet_1_1Repository.html#cb20665e4d1142b8238574e870459080" title="queue policy Bundle comparator">comp_</a> = qc; <a name="l00038"></a>00038 } <a name="l00039"></a>00039 <a name="l00040"></a>00040 <span class="keywordflow">if</span> (list != NULL) <a name="l00041"></a>00041 <span class="keywordflow">for</span>(<a class="code" href="classprophet_1_1Repository.html#979d0a33179bc3894e60816e71591ef9">const_iterator</a> i = list->begin(); i != list->end(); i++) <a name="l00042"></a>00042 <span class="keyword">add</span>(*i); <a name="l00043"></a>00043 } <a name="l00044"></a>00044 <a name="l00045"></a><a class="code" href="classprophet_1_1Repository.html#0712f5569a82c80e81a5eabb8f1849a5">00045</a> Repository::~Repository() <a name="l00046"></a>00046 { <a name="l00047"></a>00047 <span class="keyword">delete</span> <a class="code" href="classprophet_1_1Repository.html#cb20665e4d1142b8238574e870459080" title="queue policy Bundle comparator">comp_</a>; <a name="l00048"></a>00048 } <a name="l00049"></a>00049 <a name="l00050"></a>00050 <span class="keywordtype">void</span> <a name="l00051"></a><a class="code" href="classprophet_1_1Repository.html#85630acc1cb2251b14f9e315545ce672">00051</a> <a class="code" href="classprophet_1_1Repository.html#85630acc1cb2251b14f9e315545ce672" title="Remove arbitrary Bundle from Repository, and decrement current utilization accordingly...">Repository::del</a>(<span class="keyword">const</span> <a class="code" href="classprophet_1_1Bundle.html" title="Facade interface between Prophet router and host implmentation&#39;s Bundle representation...">Bundle</a>* b) <a name="l00052"></a>00052 { <a name="l00053"></a>00053 <a class="code" href="BundleOffer_8cc.html#259e390b81bb640af4691776b15a9116">LOG</a>(LOG_DEBUG,<span class="stringliteral">"del request"</span>); <a name="l00054"></a>00054 <span class="keywordflow">if</span> (b == NULL) <a name="l00055"></a>00055 { <a name="l00056"></a>00056 <a class="code" href="BundleOffer_8cc.html#259e390b81bb640af4691776b15a9116">LOG</a>(LOG_DEBUG,<span class="stringliteral">"NULL bundle"</span>); <a name="l00057"></a>00057 <span class="keywordflow">return</span>; <a name="l00058"></a>00058 } <a name="l00059"></a>00059 <a name="l00060"></a>00060 <span class="comment">// first get iterator for b</span> <a name="l00061"></a>00061 <a class="code" href="classprophet_1_1Repository.html#0194fa44c6eb1de11a06840a8909bc56">iterator</a> i; <a name="l00062"></a>00062 <span class="keywordflow">if</span> (<a class="code" href="classprophet_1_1Repository.html#fb61e882fbfc1d8aa83f65d6ba55ca0e" title="Utility function for find.">find</a>(b,i)) <a name="l00063"></a>00063 { <a name="l00064"></a>00064 <span class="comment">// parameter may only have index set, for find</span> <a name="l00065"></a>00065 <span class="comment">// so grab the reference returned by find</span> <a name="l00066"></a>00066 b = *i; <a name="l00067"></a>00067 <span class="comment">// decrement utilization by Bundle's size</span> <a name="l00068"></a>00068 <a class="code" href="classprophet_1_1Repository.html#e39fe77b424c3bf6e2c9a12aec55dc7d" title="current utilization">current_</a> -= b-><a class="code" href="classprophet_1_1Bundle.html#8612e4ac7f86a42a8f6619b3702e91ff" title="Accessors.">size</a>(); <a name="l00069"></a>00069 <span class="comment">// reorder sequence to preserve eviction ordering, moving</span> <a name="l00070"></a>00070 <span class="comment">// victim to last pos in vector</span> <a name="l00071"></a>00071 <a class="code" href="classprophet_1_1Repository.html#d7ed7acb85267844994fb86365c1051e" title="Heap operations.">remove_and_reheap</a>(i-<a class="code" href="classprophet_1_1Repository.html#30b8149dab50ab002643ce0a4ea8e0f7" title="array-based eviction-ordered heap of Bundles">list_</a>.begin()); <a name="l00072"></a>00072 <span class="comment">// remove victim from vector</span> <a name="l00073"></a>00073 <a class="code" href="classprophet_1_1Repository.html#30b8149dab50ab002643ce0a4ea8e0f7" title="array-based eviction-ordered heap of Bundles">list_</a>.pop_back(); <a name="l00074"></a>00074 <a class="code" href="BundleOffer_8cc.html#259e390b81bb640af4691776b15a9116">LOG</a>(LOG_DEBUG,<span class="stringliteral">"removed %d from list"</span>,b-><a class="code" href="classprophet_1_1Bundle.html#8f4fad2c83696237207ba7a19acb9ca4" title="Accessors.">sequence_num</a>()); <a name="l00075"></a>00075 } <a name="l00076"></a>00076 } <a name="l00077"></a>00077 <a name="l00078"></a>00078 <span class="keywordtype">bool</span> <a name="l00079"></a><a class="code" href="classprophet_1_1Repository.html#1cafd561e6fe753ab2c47e9ac0147610">00079</a> <a class="code" href="dtnperf-client_8c.html#517b0f7cbe789371f38fd9f87f8c807b">Repository::add</a>(<span class="keyword">const</span> <a class="code" href="classprophet_1_1Bundle.html" title="Facade interface between Prophet router and host implmentation&#39;s Bundle representation...">Bundle</a>* b) <a name="l00080"></a>00080 { <a name="l00081"></a>00081 <a class="code" href="BundleOffer_8cc.html#259e390b81bb640af4691776b15a9116">LOG</a>(LOG_DEBUG, <span class="stringliteral">"add request"</span>); <a name="l00082"></a>00082 <span class="keywordflow">if</span> (b == NULL) <a name="l00083"></a>00083 { <a name="l00084"></a>00084 <a class="code" href="BundleOffer_8cc.html#259e390b81bb640af4691776b15a9116">LOG</a>(LOG_DEBUG,<span class="stringliteral">"NULL bundle"</span>); <a name="l00085"></a>00085 <span class="keywordflow">return</span> <span class="keyword">false</span>; <a name="l00086"></a>00086 } <a name="l00087"></a>00087 <a name="l00088"></a>00088 <span class="comment">// duplicates not allowed</span> <a name="l00089"></a>00089 <a class="code" href="classprophet_1_1Repository.html#0194fa44c6eb1de11a06840a8909bc56">iterator</a> i; <a name="l00090"></a>00090 <span class="keywordflow">if</span> (<a class="code" href="classprophet_1_1Repository.html#fb61e882fbfc1d8aa83f65d6ba55ca0e" title="Utility function for find.">find</a>(b,i)) <a name="l00091"></a>00091 <span class="keywordflow">return</span> <span class="keyword">false</span>; <a name="l00092"></a>00092 <a name="l00093"></a>00093 <span class="comment">// add to underlying sequence</span> <a name="l00094"></a>00094 <a class="code" href="classprophet_1_1Repository.html#30b8149dab50ab002643ce0a4ea8e0f7" title="array-based eviction-ordered heap of Bundles">list_</a>.push_back(b); <a name="l00095"></a>00095 <span class="comment">// reorder sequence to eviction order</span> <a name="l00096"></a>00096 <span class="keywordtype">size_t</span> last_pos = <a class="code" href="classprophet_1_1Repository.html#30b8149dab50ab002643ce0a4ea8e0f7" title="array-based eviction-ordered heap of Bundles">list_</a>.size() - 1; <a name="l00097"></a>00097 <a class="code" href="classprophet_1_1Repository.html#05490d99aca837b83e8e951cf302e9b8" title="Heap operations.">push_heap</a>(0,last_pos,0,<a class="code" href="classprophet_1_1Repository.html#30b8149dab50ab002643ce0a4ea8e0f7" title="array-based eviction-ordered heap of Bundles">list_</a>[last_pos]); <a name="l00098"></a>00098 <span class="comment">// increment utilization by this Bundle's size</span> <a name="l00099"></a>00099 <a class="code" href="classprophet_1_1Repository.html#e39fe77b424c3bf6e2c9a12aec55dc7d" title="current utilization">current_</a> += b-><a class="code" href="classprophet_1_1Bundle.html#8612e4ac7f86a42a8f6619b3702e91ff" title="Accessors.">size</a>(); <a name="l00100"></a>00100 <span class="comment">// maintain quota</span> <a name="l00101"></a>00101 <span class="keywordflow">if</span> (<a class="code" href="classprophet_1_1Repository.html#40ace45bc3475f088b007a693fbe346e" title="facade interface into Bundle host">core_</a>-><a class="code" href="classprophet_1_1Repository_1_1BundleCoreRep.html#bff8d97a63fbd0fc0941e7e39f8f2198">max_bundle_quota</a>() > 0) <a name="l00102"></a>00102 <span class="keywordflow">while</span> (<a class="code" href="classprophet_1_1Repository.html#40ace45bc3475f088b007a693fbe346e" title="facade interface into Bundle host">core_</a>-><a class="code" href="classprophet_1_1Repository_1_1BundleCoreRep.html#bff8d97a63fbd0fc0941e7e39f8f2198">max_bundle_quota</a>() < <a class="code" href="classprophet_1_1Repository.html#e39fe77b424c3bf6e2c9a12aec55dc7d" title="current utilization">current_</a>) <a name="l00103"></a>00103 <a class="code" href="classprophet_1_1Repository.html#7369ce2c18b82ea116377d4edb838509" title="Evict the next candidate Bundle according to policy order.">evict</a>(); <a name="l00104"></a>00104 <span class="keywordflow">return</span> <span class="keyword">true</span>; <a name="l00105"></a>00105 } <a name="l00106"></a>00106 <a name="l00107"></a>00107 <span class="keywordtype">void</span> <a name="l00108"></a><a class="code" href="classprophet_1_1Repository.html#cc753727bc152f8e95a6871b93c6195b">00108</a> <a class="code" href="classprophet_1_1Repository.html#cc753727bc152f8e95a6871b93c6195b" title="Change policy of Repository by replacing comparator; post condition is that eviction...">Repository::set_comparator</a>(<a class="code" href="classprophet_1_1QueueComp.html" title="Bundle queuing policy requires a sort order, which is provided by QueueComp and its...">QueueComp</a>* qc) <a name="l00109"></a>00109 { <a name="l00110"></a>00110 <span class="keywordflow">if</span> (qc == NULL) <span class="keywordflow">return</span>; <a name="l00111"></a>00111 <a class="code" href="BundleOffer_8cc.html#259e390b81bb640af4691776b15a9116">LOG</a>(LOG_DEBUG,<span class="stringliteral">"changing policy from %s to %s"</span>, <a name="l00112"></a>00112 <a class="code" href="structprophet_1_1QueuePolicy.html#10be033bf51963571262ddccc33508be" title="Utility function to convert type code to const char*.">QueuePolicy::qp_to_str</a>(<a class="code" href="classprophet_1_1Repository.html#cb20665e4d1142b8238574e870459080" title="queue policy Bundle comparator">comp_</a>-><a class="code" href="classprophet_1_1QueueComp.html#f2dc8abe5180aaeb4724c133f29cde80" title="Accessors.">qp</a>()), <a name="l00113"></a>00113 <a class="code" href="structprophet_1_1QueuePolicy.html#10be033bf51963571262ddccc33508be" title="Utility function to convert type code to const char*.">QueuePolicy::qp_to_str</a>(qc-><a class="code" href="classprophet_1_1QueueComp.html#f2dc8abe5180aaeb4724c133f29cde80" title="Accessors.">qp</a>())); <a name="l00114"></a>00114 <span class="comment">// clean up memory</span> <a name="l00115"></a>00115 <span class="keyword">delete</span> <a class="code" href="classprophet_1_1Repository.html#cb20665e4d1142b8238574e870459080" title="queue policy Bundle comparator">comp_</a>; <a name="l00116"></a>00116 <a class="code" href="classprophet_1_1Repository.html#cb20665e4d1142b8238574e870459080" title="queue policy Bundle comparator">comp_</a> = qc; <a name="l00117"></a>00117 <span class="comment">// recalculate eviction order based on new comp_</span> <a name="l00118"></a>00118 <span class="keywordflow">if</span> (!<a class="code" href="classprophet_1_1Repository.html#30b8149dab50ab002643ce0a4ea8e0f7" title="array-based eviction-ordered heap of Bundles">list_</a>.empty()) <a name="l00119"></a>00119 <a class="code" href="classprophet_1_1Repository.html#a3ee3d3ac064fccb45e547c5c68cef67" title="Heap operations.">make_heap</a>(0, (<a class="code" href="classprophet_1_1Repository.html#30b8149dab50ab002643ce0a4ea8e0f7" title="array-based eviction-ordered heap of Bundles">list_</a>.size() - 1)); <a name="l00120"></a>00120 } <a name="l00121"></a>00121 <a name="l00122"></a>00122 <span class="keywordtype">void</span> <a name="l00123"></a><a class="code" href="classprophet_1_1Repository.html#43a57af8101bc6ae87cd903a6a56d5f8">00123</a> <a class="code" href="classprophet_1_1Repository.html#43a57af8101bc6ae87cd903a6a56d5f8" title="Callback to instruct Repository to query BundleCore on new max.">Repository::handle_change_max</a>() <a name="l00124"></a>00124 { <a name="l00125"></a>00125 <span class="comment">// enforce the new quota</span> <a name="l00126"></a>00126 <span class="keywordflow">if</span> (<a class="code" href="classprophet_1_1Repository.html#40ace45bc3475f088b007a693fbe346e" title="facade interface into Bundle host">core_</a>-><a class="code" href="classprophet_1_1Repository_1_1BundleCoreRep.html#bff8d97a63fbd0fc0941e7e39f8f2198">max_bundle_quota</a>() > 0) <a name="l00127"></a>00127 <span class="keywordflow">while</span> (<a class="code" href="classprophet_1_1Repository.html#40ace45bc3475f088b007a693fbe346e" title="facade interface into Bundle host">core_</a>-><a class="code" href="classprophet_1_1Repository_1_1BundleCoreRep.html#bff8d97a63fbd0fc0941e7e39f8f2198">max_bundle_quota</a>() < <a class="code" href="classprophet_1_1Repository.html#e39fe77b424c3bf6e2c9a12aec55dc7d" title="current utilization">current_</a>) <a name="l00128"></a>00128 <a class="code" href="classprophet_1_1Repository.html#7369ce2c18b82ea116377d4edb838509" title="Evict the next candidate Bundle according to policy order.">evict</a>(); <a name="l00129"></a>00129 } <a name="l00130"></a>00130 <a name="l00131"></a>00131 <span class="keywordtype">void</span> <a name="l00132"></a><a class="code" href="classprophet_1_1Repository.html#cd87c47df716511152d5c9da8c820de9">00132</a> <a class="code" href="classprophet_1_1Repository.html#cd87c47df716511152d5c9da8c820de9" title="Callback for external notice to recalculate eviction order for list, due to changed...">Repository::change_priority</a>(<span class="keyword">const</span> <a class="code" href="classprophet_1_1Bundle.html" title="Facade interface between Prophet router and host implmentation&#39;s Bundle representation...">Bundle</a>* b) <a name="l00133"></a>00133 { <a name="l00134"></a>00134 <a class="code" href="BundleOffer_8cc.html#259e390b81bb640af4691776b15a9116">LOG</a>(LOG_DEBUG,<span class="stringliteral">"change priority request %d"</span>, <a name="l00135"></a>00135 b == NULL ? 0 : b-><a class="code" href="classprophet_1_1Bundle.html#8f4fad2c83696237207ba7a19acb9ca4" title="Accessors.">sequence_num</a>()); <a name="l00136"></a>00136 <a name="l00137"></a>00137 <span class="keywordflow">if</span> (b == NULL) <a name="l00138"></a>00138 <span class="keywordflow">return</span>; <a name="l00139"></a>00139 <a name="l00140"></a>00140 <a class="code" href="classprophet_1_1Repository.html#0194fa44c6eb1de11a06840a8909bc56">iterator</a> i = <a class="code" href="classprophet_1_1Repository.html#30b8149dab50ab002643ce0a4ea8e0f7" title="array-based eviction-ordered heap of Bundles">list_</a>.begin(); <a name="l00141"></a>00141 <span class="comment">// brute-force search since heap property is violated</span> <a name="l00142"></a>00142 <span class="keywordflow">while</span> (i != <a class="code" href="classprophet_1_1Repository.html#30b8149dab50ab002643ce0a4ea8e0f7" title="array-based eviction-ordered heap of Bundles">list_</a>.end()) <a name="l00143"></a>00143 <span class="keywordflow">if</span> (*(*i) == *b) <a name="l00144"></a>00144 <span class="keywordflow">break</span>; <a name="l00145"></a>00145 <span class="keywordflow">else</span> i++; <a name="l00146"></a>00146 <a name="l00147"></a>00147 <span class="keywordflow">if</span> (i != <a class="code" href="classprophet_1_1Repository.html#30b8149dab50ab002643ce0a4ea8e0f7" title="array-based eviction-ordered heap of Bundles">list_</a>.end()) <a name="l00148"></a>00148 { <a name="l00149"></a>00149 <span class="comment">// pull bundle out of the heap and stick it at the end of list_</span> <a name="l00150"></a>00150 <a class="code" href="classprophet_1_1Repository.html#d7ed7acb85267844994fb86365c1051e" title="Heap operations.">remove_and_reheap</a>(i - <a class="code" href="classprophet_1_1Repository.html#30b8149dab50ab002643ce0a4ea8e0f7" title="array-based eviction-ordered heap of Bundles">list_</a>.begin()); <a name="l00151"></a>00151 <span class="comment">// pull bundle from end of list_ and put it in heapified pos</span> <a name="l00152"></a>00152 <a class="code" href="classprophet_1_1Repository.html#05490d99aca837b83e8e951cf302e9b8" title="Heap operations.">push_heap</a>(0,<a class="code" href="classprophet_1_1Repository.html#30b8149dab50ab002643ce0a4ea8e0f7" title="array-based eviction-ordered heap of Bundles">list_</a>.size() - 1,0,b); <a name="l00153"></a>00153 } <a name="l00154"></a>00154 } <a name="l00155"></a>00155 <a name="l00156"></a>00156 <span class="keywordtype">void</span> <a name="l00157"></a><a class="code" href="classprophet_1_1Repository.html#7369ce2c18b82ea116377d4edb838509">00157</a> <a class="code" href="classprophet_1_1Repository.html#7369ce2c18b82ea116377d4edb838509" title="Evict the next candidate Bundle according to policy order.">Repository::evict</a>() <a name="l00158"></a>00158 { <a name="l00159"></a>00159 <span class="keywordflow">if</span> (<a class="code" href="classprophet_1_1Repository.html#cb20665e4d1142b8238574e870459080" title="queue policy Bundle comparator">comp_</a>-><a class="code" href="classprophet_1_1QueueComp.html#f2dc8abe5180aaeb4724c133f29cde80" title="Accessors.">qp</a>() != <a class="code" href="structprophet_1_1QueuePolicy.html#41e2705af81c561ed69d802afa47ed68a7cf7e5bdd10d1048fb623a737cfe6af">QueuePolicy::LEPR</a>) <a name="l00160"></a>00160 { <a name="l00161"></a>00161 do_evict: <a name="l00162"></a>00162 <span class="keywordtype">size_t</span> last_pos = <a class="code" href="classprophet_1_1Repository.html#30b8149dab50ab002643ce0a4ea8e0f7" title="array-based eviction-ordered heap of Bundles">list_</a>.size() - 1; <a name="l00163"></a>00163 <span class="comment">// re-order so that eviction candidate is now at the end of list_</span> <a name="l00164"></a>00164 <a class="code" href="classprophet_1_1Repository.html#3080a9f8198447ef342f7050f7222406" title="Heap operations.">pop_heap</a>(0, last_pos, last_pos, <a class="code" href="classprophet_1_1Repository.html#30b8149dab50ab002643ce0a4ea8e0f7" title="array-based eviction-ordered heap of Bundles">list_</a>[last_pos]); <a name="l00165"></a>00165 <span class="comment">// capture a pointer to the back of list_</span> <a name="l00166"></a>00166 <span class="keyword">const</span> <a class="code" href="classprophet_1_1Bundle.html" title="Facade interface between Prophet router and host implmentation&#39;s Bundle representation...">Bundle</a>* b = <a class="code" href="classprophet_1_1Repository.html#30b8149dab50ab002643ce0a4ea8e0f7" title="array-based eviction-ordered heap of Bundles">list_</a>.back(); <a name="l00167"></a>00167 <span class="comment">// drop the last member off the end of list_</span> <a name="l00168"></a>00168 <a class="code" href="classprophet_1_1Repository.html#30b8149dab50ab002643ce0a4ea8e0f7" title="array-based eviction-ordered heap of Bundles">list_</a>.pop_back(); <a name="l00169"></a>00169 <span class="comment">// callback into Bundle core to request deletion of Bundle</span> <a name="l00170"></a>00170 <a class="code" href="classprophet_1_1Repository.html#40ace45bc3475f088b007a693fbe346e" title="facade interface into Bundle host">core_</a>-><a class="code" href="classprophet_1_1Repository_1_1BundleCoreRep.html#29236b5324dc7597b6f8659d5678f88b">drop_bundle</a>(b); <a name="l00171"></a>00171 <span class="comment">// decrement current consumption by Bundle's size</span> <a name="l00172"></a>00172 <a class="code" href="classprophet_1_1Repository.html#e39fe77b424c3bf6e2c9a12aec55dc7d" title="current utilization">current_</a> -= b-><a class="code" href="classprophet_1_1Bundle.html#8612e4ac7f86a42a8f6619b3702e91ff" title="Accessors.">size</a>(); <a name="l00173"></a>00173 <a name="l00174"></a>00174 <span class="keywordflow">return</span>; <a name="l00175"></a>00175 } <a name="l00176"></a>00176 <span class="keywordflow">else</span> <a name="l00177"></a>00177 { <a name="l00178"></a>00178 <span class="comment">// LEPR adds the burden of checking for NF > min_NF</span> <a name="l00179"></a>00179 <a name="l00180"></a>00180 <span class="comment">// search heap tree from top down, left to right (linearly thru vector)</span> <a name="l00181"></a>00181 <span class="keywordtype">size_t</span> <a class="code" href="num2sdnv_8c.html#fed088663f8704004425cdae2120b9b3">len</a> = <a class="code" href="classprophet_1_1Repository.html#30b8149dab50ab002643ce0a4ea8e0f7" title="array-based eviction-ordered heap of Bundles">list_</a>.size(); <a name="l00182"></a>00182 <span class="keywordflow">for</span> (<span class="keywordtype">size_t</span> pos = 0; pos < len; pos++) <a name="l00183"></a>00183 { <a name="l00184"></a>00184 <span class="keyword">const</span> <a class="code" href="classprophet_1_1Bundle.html" title="Facade interface between Prophet router and host implmentation&#39;s Bundle representation...">Bundle</a>* b = <a class="code" href="classprophet_1_1Repository.html#30b8149dab50ab002643ce0a4ea8e0f7" title="array-based eviction-ordered heap of Bundles">list_</a>[pos]; <a name="l00185"></a>00185 <span class="keywordflow">if</span> (<a class="code" href="classprophet_1_1Repository.html#cb20665e4d1142b8238574e870459080" title="queue policy Bundle comparator">comp_</a>-><a class="code" href="classprophet_1_1QueueComp.html#7b83d3e5f1939e88b62664de74a93a14" title="Only evict bundles whose NF &gt; min_fwd_.">min_fwd_</a> < b-><a class="code" href="classprophet_1_1Bundle.html#3308fba98e051cf1addc960912d75cca" title="Accessors.">num_forward</a>()) <a name="l00186"></a>00186 { <a name="l00187"></a>00187 <span class="comment">// victim is found, now evict</span> <a name="l00188"></a>00188 <span class="comment">// decrement utilization by Bundle's size</span> <a name="l00189"></a>00189 <a class="code" href="classprophet_1_1Repository.html#e39fe77b424c3bf6e2c9a12aec55dc7d" title="current utilization">current_</a> -= b-><a class="code" href="classprophet_1_1Bundle.html#8612e4ac7f86a42a8f6619b3702e91ff" title="Accessors.">size</a>(); <a name="l00190"></a>00190 <span class="comment">// reorder sequence to preserve eviction ordering, moving</span> <a name="l00191"></a>00191 <span class="comment">// victim to last pos in vector</span> <a name="l00192"></a>00192 <a class="code" href="classprophet_1_1Repository.html#d7ed7acb85267844994fb86365c1051e" title="Heap operations.">remove_and_reheap</a>(pos); <a name="l00193"></a>00193 <span class="comment">// remove victim from vector</span> <a name="l00194"></a>00194 <a class="code" href="classprophet_1_1Repository.html#30b8149dab50ab002643ce0a4ea8e0f7" title="array-based eviction-ordered heap of Bundles">list_</a>.pop_back(); <a name="l00195"></a>00195 <span class="keywordflow">return</span>; <a name="l00196"></a>00196 } <a name="l00197"></a>00197 } <a name="l00198"></a>00198 <span class="comment">// Here's where Prophet doesn't say what to do: the entire heap was</span> <a name="l00199"></a>00199 <span class="comment">// searched, but no victims qualified, due to the min_NF constraint.</span> <a name="l00200"></a>00200 <span class="comment">// Since eviction must happen, then override the min_NF requirement</span> <a name="l00201"></a>00201 <span class="comment">// and let's go ahead and evict top()</span> <a name="l00202"></a>00202 <span class="comment">// This stinks; we've already paid linear, now we pay another log on</span> <a name="l00203"></a>00203 <span class="comment">// top of that.</span> <a name="l00204"></a>00204 <span class="keywordflow">goto</span> do_evict; <a name="l00205"></a>00205 } <a name="l00206"></a>00206 } <a name="l00207"></a>00207 <a name="l00208"></a>00208 <span class="keywordtype">void</span> <a name="l00209"></a><a class="code" href="classprophet_1_1Repository.html#05490d99aca837b83e8e951cf302e9b8">00209</a> <a class="code" href="classprophet_1_1Repository.html#05490d99aca837b83e8e951cf302e9b8" title="Heap operations.">Repository::push_heap</a>(<span class="keywordtype">size_t</span> first, <span class="keywordtype">size_t</span> hole, <span class="keywordtype">size_t</span> top, <span class="keyword">const</span> <a class="code" href="classprophet_1_1Bundle.html" title="Facade interface between Prophet router and host implmentation&#39;s Bundle representation...">Bundle</a>* b) <a name="l00210"></a>00210 { <a name="l00211"></a>00211 <span class="keywordtype">size_t</span> parent = (hole - 1) / 2; <a name="l00212"></a>00212 <span class="keywordflow">while</span> (hole > top && (*<a class="code" href="classprophet_1_1Repository.html#cb20665e4d1142b8238574e870459080" title="queue policy Bundle comparator">comp_</a>)(<a class="code" href="classprophet_1_1Repository.html#30b8149dab50ab002643ce0a4ea8e0f7" title="array-based eviction-ordered heap of Bundles">list_</a>[first + parent],b)) <a name="l00213"></a>00213 { <a name="l00214"></a>00214 <a class="code" href="classprophet_1_1Repository.html#30b8149dab50ab002643ce0a4ea8e0f7" title="array-based eviction-ordered heap of Bundles">list_</a>[first + hole] = <a class="code" href="classprophet_1_1Repository.html#30b8149dab50ab002643ce0a4ea8e0f7" title="array-based eviction-ordered heap of Bundles">list_</a>[first + parent]; <a name="l00215"></a>00215 hole = parent; <a name="l00216"></a>00216 parent = (hole - 1) / 2; <a name="l00217"></a>00217 } <a name="l00218"></a>00218 <a class="code" href="classprophet_1_1Repository.html#30b8149dab50ab002643ce0a4ea8e0f7" title="array-based eviction-ordered heap of Bundles">list_</a>[first + hole] = b; <a name="l00219"></a>00219 } <a name="l00220"></a>00220 <a name="l00221"></a>00221 <span class="keywordtype">void</span> <a name="l00222"></a><a class="code" href="classprophet_1_1Repository.html#3080a9f8198447ef342f7050f7222406">00222</a> <a class="code" href="classprophet_1_1Repository.html#3080a9f8198447ef342f7050f7222406" title="Heap operations.">Repository::pop_heap</a>(<span class="keywordtype">size_t</span> first, <span class="keywordtype">size_t</span> last, <span class="keywordtype">size_t</span> result, <span class="keyword">const</span> <a class="code" href="classprophet_1_1Bundle.html" title="Facade interface between Prophet router and host implmentation&#39;s Bundle representation...">Bundle</a>* b) <a name="l00223"></a>00223 { <a name="l00224"></a>00224 <a class="code" href="classprophet_1_1Repository.html#30b8149dab50ab002643ce0a4ea8e0f7" title="array-based eviction-ordered heap of Bundles">list_</a>[result] = <a class="code" href="classprophet_1_1Repository.html#30b8149dab50ab002643ce0a4ea8e0f7" title="array-based eviction-ordered heap of Bundles">list_</a>[first]; <a name="l00225"></a>00225 <a class="code" href="classprophet_1_1Repository.html#9867f5529bdd391f9cf89df552912cde" title="Heap operations.">adjust_heap</a>(first, 0, last - first, b); <a name="l00226"></a>00226 } <a name="l00227"></a>00227 <a name="l00228"></a>00228 <span class="keywordtype">void</span> <a name="l00229"></a><a class="code" href="classprophet_1_1Repository.html#9867f5529bdd391f9cf89df552912cde">00229</a> <a class="code" href="classprophet_1_1Repository.html#9867f5529bdd391f9cf89df552912cde" title="Heap operations.">Repository::adjust_heap</a>(<span class="keywordtype">size_t</span> first, <span class="keywordtype">size_t</span> hole, <span class="keywordtype">size_t</span> <a class="code" href="num2sdnv_8c.html#fed088663f8704004425cdae2120b9b3">len</a>, <span class="keyword">const</span> <a class="code" href="classprophet_1_1Bundle.html" title="Facade interface between Prophet router and host implmentation&#39;s Bundle representation...">Bundle</a>* b) <a name="l00230"></a>00230 { <a name="l00231"></a>00231 <span class="comment">// size 0 or 1 is already a valid heap!</span> <a name="l00232"></a>00232 <span class="keywordflow">if</span> (<a class="code" href="classprophet_1_1Repository.html#30b8149dab50ab002643ce0a4ea8e0f7" title="array-based eviction-ordered heap of Bundles">list_</a>.size() < 2) <a name="l00233"></a>00233 <span class="keywordflow">return</span>; <a name="l00234"></a>00234 <a name="l00235"></a>00235 <span class="keyword">const</span> <span class="keywordtype">size_t</span> top = hole; <a name="l00236"></a>00236 <span class="keywordtype">size_t</span> second = 2 * hole + 2; <a name="l00237"></a>00237 <span class="keywordflow">while</span> (second < len) <a name="l00238"></a>00238 { <a name="l00239"></a>00239 <span class="keywordflow">if</span> ((*<a class="code" href="classprophet_1_1Repository.html#cb20665e4d1142b8238574e870459080" title="queue policy Bundle comparator">comp_</a>)(<a class="code" href="classprophet_1_1Repository.html#30b8149dab50ab002643ce0a4ea8e0f7" title="array-based eviction-ordered heap of Bundles">list_</a>[first + second], <a class="code" href="classprophet_1_1Repository.html#30b8149dab50ab002643ce0a4ea8e0f7" title="array-based eviction-ordered heap of Bundles">list_</a>[first + (second - 1)])) <a name="l00240"></a>00240 second--; <a name="l00241"></a>00241 <a class="code" href="classprophet_1_1Repository.html#30b8149dab50ab002643ce0a4ea8e0f7" title="array-based eviction-ordered heap of Bundles">list_</a>[first + hole] = <a class="code" href="classprophet_1_1Repository.html#30b8149dab50ab002643ce0a4ea8e0f7" title="array-based eviction-ordered heap of Bundles">list_</a>[first + second]; <a name="l00242"></a>00242 hole = second; <a name="l00243"></a>00243 second = 2 * (second + 1); <a name="l00244"></a>00244 } <a name="l00245"></a>00245 <span class="keywordflow">if</span> (second == len) <a name="l00246"></a>00246 { <a name="l00247"></a>00247 <a class="code" href="classprophet_1_1Repository.html#30b8149dab50ab002643ce0a4ea8e0f7" title="array-based eviction-ordered heap of Bundles">list_</a>[first + hole] = <a class="code" href="classprophet_1_1Repository.html#30b8149dab50ab002643ce0a4ea8e0f7" title="array-based eviction-ordered heap of Bundles">list_</a>[first + (second - 1)]; <a name="l00248"></a>00248 hole = second - 1; <a name="l00249"></a>00249 } <a name="l00250"></a>00250 <a class="code" href="classprophet_1_1Repository.html#05490d99aca837b83e8e951cf302e9b8" title="Heap operations.">push_heap</a>(first, hole, top, b); <a name="l00251"></a>00251 } <a name="l00252"></a>00252 <a name="l00253"></a>00253 <span class="keywordtype">void</span> <a name="l00254"></a><a class="code" href="classprophet_1_1Repository.html#d7ed7acb85267844994fb86365c1051e">00254</a> <a class="code" href="classprophet_1_1Repository.html#d7ed7acb85267844994fb86365c1051e" title="Heap operations.">Repository::remove_and_reheap</a>(<span class="keywordtype">size_t</span> hole) <a name="l00255"></a>00255 { <a name="l00256"></a>00256 <span class="comment">// overwrite victim with lowest ranking leaf</span> <a name="l00257"></a>00257 <a class="code" href="classprophet_1_1Repository.html#30b8149dab50ab002643ce0a4ea8e0f7" title="array-based eviction-ordered heap of Bundles">list_</a>[hole] = <a class="code" href="classprophet_1_1Repository.html#30b8149dab50ab002643ce0a4ea8e0f7" title="array-based eviction-ordered heap of Bundles">list_</a>[<a class="code" href="classprophet_1_1Repository.html#30b8149dab50ab002643ce0a4ea8e0f7" title="array-based eviction-ordered heap of Bundles">list_</a>.size() - 1]; <a name="l00258"></a>00258 <span class="comment">// reheap downstream from hole</span> <a name="l00259"></a>00259 <a class="code" href="classprophet_1_1Repository.html#9867f5529bdd391f9cf89df552912cde" title="Heap operations.">adjust_heap</a>(0, hole, <a class="code" href="classprophet_1_1Repository.html#30b8149dab50ab002643ce0a4ea8e0f7" title="array-based eviction-ordered heap of Bundles">list_</a>.size() - 2, <a class="code" href="classprophet_1_1Repository.html#30b8149dab50ab002643ce0a4ea8e0f7" title="array-based eviction-ordered heap of Bundles">list_</a>[hole]); <a name="l00260"></a>00260 } <a name="l00261"></a>00261 <a name="l00262"></a>00262 <span class="keywordtype">void</span> <a name="l00263"></a><a class="code" href="classprophet_1_1Repository.html#a3ee3d3ac064fccb45e547c5c68cef67">00263</a> <a class="code" href="classprophet_1_1Repository.html#a3ee3d3ac064fccb45e547c5c68cef67" title="Heap operations.">Repository::make_heap</a>(<span class="keywordtype">size_t</span> first, <span class="keywordtype">size_t</span> last) <a name="l00264"></a>00264 { <a name="l00265"></a>00265 <span class="comment">// size 0 or 1 is already a valid heap!</span> <a name="l00266"></a>00266 <span class="keywordflow">if</span> (last < first + 2) <span class="keywordflow">return</span>; <a name="l00267"></a>00267 <a name="l00268"></a>00268 <span class="keywordtype">size_t</span> <a class="code" href="num2sdnv_8c.html#fed088663f8704004425cdae2120b9b3">len</a> = last - first; <a name="l00269"></a>00269 <span class="keywordtype">size_t</span> parent = (len - 2) / 2; <a name="l00270"></a>00270 <span class="keywordflow">while</span> (<span class="keyword">true</span>) <a name="l00271"></a>00271 { <a name="l00272"></a>00272 <a class="code" href="classprophet_1_1Repository.html#9867f5529bdd391f9cf89df552912cde" title="Heap operations.">adjust_heap</a>(first, parent, len, <a class="code" href="classprophet_1_1Repository.html#30b8149dab50ab002643ce0a4ea8e0f7" title="array-based eviction-ordered heap of Bundles">list_</a>[first + parent]); <a name="l00273"></a>00273 <span class="keywordflow">if</span> (parent == 0) <span class="keywordflow">break</span>; <a name="l00274"></a>00274 parent--; <a name="l00275"></a>00275 } <a name="l00276"></a>00276 } <a name="l00277"></a>00277 <a name="l00278"></a>00278 <span class="keywordtype">bool</span> <a name="l00279"></a><a class="code" href="classprophet_1_1Repository.html#fb61e882fbfc1d8aa83f65d6ba55ca0e">00279</a> <a class="code" href="classprophet_1_1Repository.html#fb61e882fbfc1d8aa83f65d6ba55ca0e" title="Utility function for find.">Repository::find</a>(<span class="keyword">const</span> <a class="code" href="classprophet_1_1Bundle.html" title="Facade interface between Prophet router and host implmentation&#39;s Bundle representation...">Bundle</a>* b, <a class="code" href="classprophet_1_1Repository.html#0194fa44c6eb1de11a06840a8909bc56">iterator</a>& i) <a name="l00280"></a>00280 { <a name="l00281"></a>00281 <span class="keywordflow">if</span> (<a class="code" href="classprophet_1_1Repository.html#30b8149dab50ab002643ce0a4ea8e0f7" title="array-based eviction-ordered heap of Bundles">list_</a>.empty()) <span class="keywordflow">return</span> <span class="keyword">false</span>; <a name="l00282"></a>00282 <a name="l00283"></a>00283 i = <a class="code" href="classprophet_1_1Repository.html#30b8149dab50ab002643ce0a4ea8e0f7" title="array-based eviction-ordered heap of Bundles">list_</a>.begin(); <a name="l00284"></a>00284 <span class="keywordflow">while</span> (i != <a class="code" href="classprophet_1_1Repository.html#30b8149dab50ab002643ce0a4ea8e0f7" title="array-based eviction-ordered heap of Bundles">list_</a>.end()) <a name="l00285"></a>00285 <span class="keywordflow">if</span> (b == *i) <a name="l00286"></a>00286 <span class="keywordflow">break</span>; <a name="l00287"></a>00287 <span class="keywordflow">else</span> <a name="l00288"></a>00288 i++; <a name="l00289"></a>00289 <span class="keywordflow">return</span> (i != <a class="code" href="classprophet_1_1Repository.html#30b8149dab50ab002643ce0a4ea8e0f7" title="array-based eviction-ordered heap of Bundles">list_</a>.end() && b == *i); <a name="l00290"></a>00290 } <a name="l00291"></a>00291 <a name="l00292"></a>00292 }; <span class="comment">// namespace prophet</span> </pre></div></div> <hr size="1"><address style="text-align: right;"><small>Generated on Mon Jul 21 14:09:46 2008 for DTN Reference Implementation by <a href="http://www.doxygen.org/index.html"> <img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.6 </small></address> </body> </html>