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
 <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> <span class="preprocessor">#ifndef dsa_BinaryIndexTree_H__</span></div>
<div class="line"><a name="l00002"></a><span class="lineno"> 2</span> <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> <span class="preprocessor"></span></div>
<div class="line"><a name="l00004"></a><span class="lineno"> 4</span> <span class="preprocessor">#include <cstdlib></span></div>
<div class="line"><a name="l00005"></a><span class="lineno"> 5</span> </div>
<div class="line"><a name="l00006"></a><span class="lineno"> 6</span> <span class="preprocessor">#include <vector></span></div>
<div class="line"><a name="l00007"></a><span class="lineno"> 7</span> <span class="preprocessor">#include <algorithm></span></div>
<div class="line"><a name="l00008"></a><span class="lineno"> 8</span> </div>
<div class="line"><a name="l00009"></a><span class="lineno"> 9</span> <span class="keyword">namespace </span>meow {</div>
<div class="line"><a name="l00010"></a><span class="lineno"> 10</span> </div>
<div class="line"><a name="l00011"></a><span class="lineno"> 11</span> <span class="keyword">template</span><<span class="keyword">class</span> Value></div>
<div class="line"><a name="l00021"></a><span class="lineno"><a class="code" href="classmeow_1_1BinaryIndexTree.html"> 21</a></span> <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> <span class="keyword">private</span>:</div>
<div class="line"><a name="l00023"></a><span class="lineno"> 23</span>  std::vector<Value> array_;</div>
<div class="line"><a name="l00024"></a><span class="lineno"> 24</span> <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>  <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>  }</div>
<div class="line"><a name="l00030"></a><span class="lineno"> 30</span> </div>
<div class="line"><a name="l00037"></a><span class="lineno"><a class="code" href="classmeow_1_1BinaryIndexTree.html#a355a4eacbfbe2112720d529efdbad021"> 37</a></span>  <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>& value):</div>
<div class="line"><a name="l00038"></a><span class="lineno"> 38</span>  array_(size, value) {</div>
<div class="line"><a name="l00039"></a><span class="lineno"> 39</span>  }</div>
<div class="line"><a name="l00040"></a><span class="lineno"> 40</span> </div>
<div class="line"><a name="l00047"></a><span class="lineno"><a class="code" href="classmeow_1_1BinaryIndexTree.html#a8323caade12e478be1e47b7612a60b8f"> 47</a></span>  <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>& tree2):</div>
<div class="line"><a name="l00048"></a><span class="lineno"> 48</span>  array_(tree2.array_) {</div>
<div class="line"><a name="l00049"></a><span class="lineno"> 49</span>  }</div>
<div class="line"><a name="l00050"></a><span class="lineno"> 50</span> </div>
<div class="line"><a name="l00060"></a><span class="lineno"><a class="code" href="classmeow_1_1BinaryIndexTree.html#a5634a9420ee864860bbf8605b9e17c32"> 60</a></span>  <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>& init) {</div>
<div class="line"><a name="l00061"></a><span class="lineno"> 61</span>  array_.clear();</div>
<div class="line"><a name="l00062"></a><span class="lineno"> 62</span>  array_.resize(size, init);</div>
<div class="line"><a name="l00063"></a><span class="lineno"> 63</span>  }</div>
<div class="line"><a name="l00064"></a><span class="lineno"> 64</span> </div>
<div class="line"><a name="l00074"></a><span class="lineno"><a class="code" href="classmeow_1_1BinaryIndexTree.html#a3a4f1799b20d5dab24d8cc584db5d32d"> 74</a></span>  <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>& value) {</div>
<div class="line"><a name="l00075"></a><span class="lineno"> 75</span>  index++;</div>
<div class="line"><a name="l00076"></a><span class="lineno"> 76</span>  <span class="keywordflow">for</span> ( ; index <= array_.size(); index += (index & -index)) {</div>
<div class="line"><a name="l00077"></a><span class="lineno"> 77</span>  array_[index - 1] = array_[index - 1] + value;</div>
<div class="line"><a name="l00078"></a><span class="lineno"> 78</span>  }</div>
<div class="line"><a name="l00079"></a><span class="lineno"> 79</span>  }</div>
<div class="line"><a name="l00080"></a><span class="lineno"> 80</span> </div>
<div class="line"><a name="l00081"></a><span class="lineno"> 81</span> </div>
<div class="line"><a name="l00090"></a><span class="lineno"><a class="code" href="classmeow_1_1BinaryIndexTree.html#a99f7d954c32c0292a9dda4b74abe5833"> 90</a></span>  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>  index = std::min(index + 1, (ssize_t)array_.size());</div>
<div class="line"><a name="l00092"></a><span class="lineno"> 92</span>  Value ret(0);</div>
<div class="line"><a name="l00093"></a><span class="lineno"> 93</span>  <span class="keywordflow">for</span> ( ; 0 < index; index -= (index & -index)) {</div>
<div class="line"><a name="l00094"></a><span class="lineno"> 94</span>  ret = ret + array_[index - 1];</div>
<div class="line"><a name="l00095"></a><span class="lineno"> 95</span>  }</div>
<div class="line"><a name="l00096"></a><span class="lineno"> 96</span>  <span class="keywordflow">return</span> ret;</div>
<div class="line"><a name="l00097"></a><span class="lineno"> 97</span>  }</div>
<div class="line"><a name="l00098"></a><span class="lineno"> 98</span> };</div>
<div class="line"><a name="l00099"></a><span class="lineno"> 99</span> </div>
<div class="line"><a name="l00100"></a><span class="lineno"> 100</span> }</div>
<div class="line"><a name="l00101"></a><span class="lineno"> 101</span> </div>
<div class="line"><a name="l00102"></a><span class="lineno"> 102</span> <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>
|