aboutsummaryrefslogtreecommitdiffstats
path: root/doc/html/BinaryIndexTree_8h_source.html
blob: 193f571ec2febdf482e88c0bf31082aefda3e687 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
<!-- HTML header for doxygen 1.8.3.1-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.3.1"/>
<title>Templates -- Meow: meowpp/dsa/BinaryIndexTree.h Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
  $(window).load(resizeHeight);
</script>
<link href="stylesheet.css" rel="stylesheet" type="text/css" />
<link href="custom.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectlogo"><img alt="Logo" src="logo.png"/></td>
  <td style="padding-left: 0.5em;">
   <div id="projectname">Templates -- Meow
   &#160;<span id="projectnumber">1.1.2</span>
   </div>
   <div id="projectbrief">不能,也不應該先編譯成obj-file的templates</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.3.1 -->
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
$(document).ready(function(){initNavTree('BinaryIndexTree_8h_source.html','');});
</script>
<div id="doc-content">
<div class="header">
  <div class="headertitle">
<div class="title">BinaryIndexTree.h</div>  </div>
</div><!--header-->
<div class="contents">
<a href="BinaryIndexTree_8h.html">Go to the documentation of this file.</a><div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno">    1</span>&#160;<span class="preprocessor">#ifndef   dsa_BinaryIndexTree_H__</span></div>
<div class="line"><a name="l00002"></a><span class="lineno">    2</span>&#160;<span class="preprocessor"></span><span class="preprocessor">#define   dsa_BinaryIndexTree_H__</span></div>
<div class="line"><a name="l00003"></a><span class="lineno">    3</span>&#160;<span class="preprocessor"></span></div>
<div class="line"><a name="l00004"></a><span class="lineno">    4</span>&#160;<span class="preprocessor">#include &lt;cstdlib&gt;</span></div>
<div class="line"><a name="l00005"></a><span class="lineno">    5</span>&#160;</div>
<div class="line"><a name="l00006"></a><span class="lineno">    6</span>&#160;<span class="preprocessor">#include &lt;vector&gt;</span></div>
<div class="line"><a name="l00007"></a><span class="lineno">    7</span>&#160;<span class="preprocessor">#include &lt;algorithm&gt;</span></div>
<div class="line"><a name="l00008"></a><span class="lineno">    8</span>&#160;</div>
<div class="line"><a name="l00009"></a><span class="lineno">    9</span>&#160;<span class="keyword">namespace </span>meow {</div>
<div class="line"><a name="l00010"></a><span class="lineno">   10</span>&#160;</div>
<div class="line"><a name="l00011"></a><span class="lineno">   11</span>&#160;<span class="keyword">template</span>&lt;<span class="keyword">class</span> Value&gt;</div>
<div class="line"><a name="l00021"></a><span class="lineno"><a class="code" href="classmeow_1_1BinaryIndexTree.html">   21</a></span>&#160;<span class="keyword">class </span><a class="code" href="classmeow_1_1BinaryIndexTree.html" title="極度簡化的 SegmentTree 已無區間更新的操作">BinaryIndexTree</a> {</div>
<div class="line"><a name="l00022"></a><span class="lineno">   22</span>&#160;<span class="keyword">private</span>:</div>
<div class="line"><a name="l00023"></a><span class="lineno">   23</span>&#160;  std::vector&lt;Value&gt; array_;</div>
<div class="line"><a name="l00024"></a><span class="lineno">   24</span>&#160;<span class="keyword">public</span>:</div>
<div class="line"><a name="l00028"></a><span class="lineno"><a class="code" href="classmeow_1_1BinaryIndexTree.html#afe34f33091c5c8267f1d219ff40824c4">   28</a></span>&#160;  <a class="code" href="classmeow_1_1BinaryIndexTree.html#afe34f33091c5c8267f1d219ff40824c4" title="constructor">BinaryIndexTree</a>() {</div>
<div class="line"><a name="l00029"></a><span class="lineno">   29</span>&#160;  }</div>
<div class="line"><a name="l00030"></a><span class="lineno">   30</span>&#160;</div>
<div class="line"><a name="l00037"></a><span class="lineno"><a class="code" href="classmeow_1_1BinaryIndexTree.html#a355a4eacbfbe2112720d529efdbad021">   37</a></span>&#160;  <a class="code" href="classmeow_1_1BinaryIndexTree.html#afe34f33091c5c8267f1d219ff40824c4" title="constructor">BinaryIndexTree</a>(<span class="keywordtype">size_t</span> size, Value <span class="keyword">const</span>&amp; value):</div>
<div class="line"><a name="l00038"></a><span class="lineno">   38</span>&#160;  array_(size, value) {</div>
<div class="line"><a name="l00039"></a><span class="lineno">   39</span>&#160;  }</div>
<div class="line"><a name="l00040"></a><span class="lineno">   40</span>&#160;</div>
<div class="line"><a name="l00047"></a><span class="lineno"><a class="code" href="classmeow_1_1BinaryIndexTree.html#a8323caade12e478be1e47b7612a60b8f">   47</a></span>&#160;  <a class="code" href="classmeow_1_1BinaryIndexTree.html#afe34f33091c5c8267f1d219ff40824c4" title="constructor">BinaryIndexTree</a>(<a class="code" href="classmeow_1_1BinaryIndexTree.html" title="極度簡化的 SegmentTree 已無區間更新的操作">BinaryIndexTree</a> <span class="keyword">const</span>&amp; tree2):</div>
<div class="line"><a name="l00048"></a><span class="lineno">   48</span>&#160;  array_(tree2.array_) {</div>
<div class="line"><a name="l00049"></a><span class="lineno">   49</span>&#160;  }</div>
<div class="line"><a name="l00050"></a><span class="lineno">   50</span>&#160;</div>
<div class="line"><a name="l00060"></a><span class="lineno"><a class="code" href="classmeow_1_1BinaryIndexTree.html#a5634a9420ee864860bbf8605b9e17c32">   60</a></span>&#160;  <span class="keywordtype">void</span> <a class="code" href="classmeow_1_1BinaryIndexTree.html#a5634a9420ee864860bbf8605b9e17c32" title="將資料洗掉, 重設">reset</a>(<span class="keywordtype">size_t</span> size, Value <span class="keyword">const</span>&amp; init) {</div>
<div class="line"><a name="l00061"></a><span class="lineno">   61</span>&#160;    array_.clear();</div>
<div class="line"><a name="l00062"></a><span class="lineno">   62</span>&#160;    array_.resize(size, init);</div>
<div class="line"><a name="l00063"></a><span class="lineno">   63</span>&#160;  }</div>
<div class="line"><a name="l00064"></a><span class="lineno">   64</span>&#160;</div>
<div class="line"><a name="l00074"></a><span class="lineno"><a class="code" href="classmeow_1_1BinaryIndexTree.html#a3a4f1799b20d5dab24d8cc584db5d32d">   74</a></span>&#160;  <span class="keywordtype">void</span> <a class="code" href="classmeow_1_1BinaryIndexTree.html#a3a4f1799b20d5dab24d8cc584db5d32d" title="將array中第 index (從零算起)個element多加上指定的值">update</a>(<span class="keywordtype">size_t</span> index, Value <span class="keyword">const</span>&amp; value) {</div>
<div class="line"><a name="l00075"></a><span class="lineno">   75</span>&#160;    index++;</div>
<div class="line"><a name="l00076"></a><span class="lineno">   76</span>&#160;    <span class="keywordflow">for</span> ( ; index &lt;= array_.size(); index += (index &amp; -index)) {</div>
<div class="line"><a name="l00077"></a><span class="lineno">   77</span>&#160;      array_[index - 1] = array_[index - 1] + value;</div>
<div class="line"><a name="l00078"></a><span class="lineno">   78</span>&#160;    }</div>
<div class="line"><a name="l00079"></a><span class="lineno">   79</span>&#160;  }</div>
<div class="line"><a name="l00080"></a><span class="lineno">   80</span>&#160;</div>
<div class="line"><a name="l00081"></a><span class="lineno">   81</span>&#160;</div>
<div class="line"><a name="l00090"></a><span class="lineno"><a class="code" href="classmeow_1_1BinaryIndexTree.html#a99f7d954c32c0292a9dda4b74abe5833">   90</a></span>&#160;  Value <a class="code" href="classmeow_1_1BinaryIndexTree.html#a99f7d954c32c0292a9dda4b74abe5833" title="詢問 0~index 的區間值">query</a>(ssize_t index)<span class="keyword"> const </span>{</div>
<div class="line"><a name="l00091"></a><span class="lineno">   91</span>&#160;    index = std::min(index + 1, (ssize_t)array_.size());</div>
<div class="line"><a name="l00092"></a><span class="lineno">   92</span>&#160;    Value ret(0);</div>
<div class="line"><a name="l00093"></a><span class="lineno">   93</span>&#160;    <span class="keywordflow">for</span> ( ; 0 &lt; index; index -= (index &amp; -index)) {</div>
<div class="line"><a name="l00094"></a><span class="lineno">   94</span>&#160;      ret = ret + array_[index - 1];</div>
<div class="line"><a name="l00095"></a><span class="lineno">   95</span>&#160;    }</div>
<div class="line"><a name="l00096"></a><span class="lineno">   96</span>&#160;    <span class="keywordflow">return</span> ret;</div>
<div class="line"><a name="l00097"></a><span class="lineno">   97</span>&#160;  }</div>
<div class="line"><a name="l00098"></a><span class="lineno">   98</span>&#160;};</div>
<div class="line"><a name="l00099"></a><span class="lineno">   99</span>&#160;</div>
<div class="line"><a name="l00100"></a><span class="lineno">  100</span>&#160;}</div>
<div class="line"><a name="l00101"></a><span class="lineno">  101</span>&#160;</div>
<div class="line"><a name="l00102"></a><span class="lineno">  102</span>&#160;<span class="preprocessor">#endif // dsa_BinaryIndexTree_H__</span></div>
</div><!-- fragment --></div><!-- contents -->
</div><!-- doc-content -->
<!-- HTML footer for doxygen 1.8.3.1-->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  <ul>
    <li class="navelem"><a class="el" href="dir_92fecd8d02dd5e7a67429447fdf0f60f.html">meowpp</a></li><li class="navelem"><a class="el" href="dir_a17ff8dcb3a1c1b842af541700214096.html">dsa</a></li><li class="navelem"><a class="el" href="BinaryIndexTree_8h.html">BinaryIndexTree.h</a></li>
    <li class="footer">Generated on Sun Jun 1 2014 13:54:33 for Templates -- Meow by
    <a href="http://www.doxygen.org/index.html">
    <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.3.1 </li>
  </ul>
</div>
</body>
</html>