锘??xml version="1.0" encoding="utf-8" standalone="yes"?>久久精品国产只有精品66,亚洲人成精品久久久久,久久婷婷国产综合精品http://www.shnenglu.com/zerolee/archive/2012/06/17/179150.htmlZero LeeZero LeeSun, 17 Jun 2012 02:37:00 GMThttp://www.shnenglu.com/zerolee/archive/2012/06/17/179150.htmlhttp://www.shnenglu.com/zerolee/comments/179150.htmlhttp://www.shnenglu.com/zerolee/archive/2012/06/17/179150.html#Feedback0http://www.shnenglu.com/zerolee/comments/commentRss/179150.htmlhttp://www.shnenglu.com/zerolee/services/trackbacks/179150.html http://en.wikipedia.org/wiki/Allocator_(C%2B%2B) 

1. 鍦℅NU C++涓紝STL allocator涓ユ牸閬靛畧C++鐨勬爣鍑嗭細
鐪嬩竴涓嬬殑浠g爜錛氾紙瀹氫箟鍦╞its/allocator.h鏂囦歡涓級
 1 namespace std
 2 {
 3   template<typename _Tp>
 4     class allocator;
 5 
 6   template<>
 7     class allocator<void>
 8     {
 9     public:
10       typedef size_t      size_type;
11       typedef ptrdiff_t   difference_type;
12       typedef void*       pointer;
13       typedef const void* const_pointer;
14       typedef void        value_type;
15 
16       template<typename _Tp1>
17         struct rebind
18         { typedef allocator<_Tp1> other; };
19     };
20 
21   /**
22    *  @brief  The "standard" allocator, as per [20.4].
23    *
24    *  (See @link Allocators allocators info @endlink for more.)
25    */
26   template<typename _Tp>
27     class allocator: public ___glibcxx_base_allocator<_Tp>
28     {
29    public:
30       typedef size_t     size_type;
31       typedef ptrdiff_t  difference_type;
32       typedef _Tp*       pointer;
33       typedef const _Tp* const_pointer;
34       typedef _Tp&       reference;
35       typedef const _Tp& const_reference;
36 
37       typedef _Tp        value_type;
38 
39       template<typename _Tp1>
40         struct rebind
41         { typedef allocator<_Tp1> other; };
42 
43       allocator() throw() { }
44 
45       allocator(const allocator& a) throw()
46       : ___glibcxx_base_allocator<_Tp>(a) { }
47 
48       template<typename _Tp1>
49         allocator(const allocator<_Tp1>&) throw() { }
50 
51       ~allocator() throw() { }
52 
53       // Inherit everything else.
54     };
55 
56   template<typename _T1, typename _T2>
57     inline bool
58     operator==(const allocator<_T1>&, const allocator<_T2>&)
59     { return true; }
60 
61   template<typename _T1, typename _T2>
62     inline bool
63     operator!=(const allocator<_T1>&, const allocator<_T2>&)
64     { return false; }
65 
66   // Inhibit implicit instantiations for required instantiations,
67   // which are defined via explicit instantiations elsewhere.
68   // NB: This syntax is a GNU extension.
69 #if _GLIBCXX_EXTERN_TEMPLATE
70   extern template class allocator<char>;
71 
72   extern template class allocator<wchar_t>;
73 #endif
74 
75   // Undefine.
76 #undef ___glibcxx_base_allocator
77 } // namespace std
78 

template ___glibcxx_base_allocator 瀹氫箟鍦ㄥ叿浣撶殑騫沖彴鐩稿叧鐨勫ご鏂囦歡涓紝渚嬪i386-redhat-linux/bits/c++allocator.h:
鍙互鐪嬪嚭GNU c++鐨刟llocator鍏跺疄閲囩敤鐨勬槸new/delete-based allocation.

 1 namespace __gnu_cxx
 2 {
 3   /**
 4    *  @brief  An allocator that uses global new, as per [20.4].
 5    *
 6    *  This is precisely the allocator defined in the C++ Standard.
 7    *    - all allocation calls operator new
 8    *    - all deallocation calls operator delete
 9    *
10    *  (See @link Allocators allocators info @endlink for more.)
11    */
12   template<typename _Tp>
13     class new_allocator
14     {
15     public:
16       typedef size_t     size_type;
17       typedef ptrdiff_t  difference_type;
18       typedef _Tp*       pointer;
19       typedef const _Tp* const_pointer;
20       typedef _Tp&       reference;
21       typedef const _Tp& const_reference;
22       typedef _Tp        value_type;
23 
24       template<typename _Tp1>
25         struct rebind
26         { typedef new_allocator<_Tp1> other; };
27 
28       new_allocator() throw() { }
29 
30       new_allocator(const new_allocator&) throw() { }
31 
32       template<typename _Tp1>
33         new_allocator(const new_allocator<_Tp1>&) throw() { }
34 
35       ~new_allocator() throw() { }
36 
37 
38       pointer
39       address(reference __x) const { return &__x; }
40 
41       const_pointer
42       address(const_reference __x) const { return &__x; }
43 
44       // NB: __n is permitted to be 0.  The C++ standard says nothing
45       // about what the return value is when __n == 0.
46       pointer
47       allocate(size_type __n, const void* = 0)
48       { return static_cast<_Tp*>(::operator new(__n * sizeof(_Tp))); }
49 
50       // __p is not permitted to be a null pointer.
51       void
52       deallocate(pointer __p, size_type)
53       { ::operator delete(__p); }
54 
55       size_type
56       max_size() const throw()
57       { return size_t(-1) / sizeof(_Tp); }
58 
59       // _GLIBCXX_RESOLVE_LIB_DEFECTS
60       // 402. wrong new expression in [some_] allocator::construct
61       void
62       construct(pointer __p, const _Tp& __val)
63       { ::new(__p) _Tp(__val); }
64 
65       void
66       destroy(pointer __p) { __p->~_Tp(); }
67     };
68 
69   template<typename _Tp>
70     inline bool
71     operator==(const new_allocator<_Tp>&, const new_allocator<_Tp>&)
72     { return true; }
73 
74 
75   template<typename _Tp>
76     inline bool
77     operator!=(const new_allocator<_Tp>&, const new_allocator<_Tp>&)
78     { return false; }
79 } // namespace __gnu_cxx
80 


Zero Lee 2012-06-17 10:37 鍙戣〃璇勮
]]>
濡備綍灝嗕竴鐗囧唴瀛橀摼鎺ユ垚閾捐〃http://www.shnenglu.com/zerolee/archive/2012/06/16/179073.htmlZero LeeZero LeeSat, 16 Jun 2012 10:38:00 GMThttp://www.shnenglu.com/zerolee/archive/2012/06/16/179073.htmlhttp://www.shnenglu.com/zerolee/comments/179073.htmlhttp://www.shnenglu.com/zerolee/archive/2012/06/16/179073.html#Feedback0http://www.shnenglu.com/zerolee/comments/commentRss/179073.htmlhttp://www.shnenglu.com/zerolee/services/trackbacks/179073.html
榪欓噷緇欏嚭SGI STL鍐呭瓨鍒嗛厤鍣ㄧ殑涓涓畝鍗曞疄鐜幫細
棣栧厛瀹氫箟涓涓猽nion鏁版嵁緇撴瀯錛?br />
1 union obj {
2     union obj* free_list_link;
3     char client_data[1];
4 };

榪欎釜union緇撴瀯浣撶殑鏈澶уぇ灝忎負4bytes 錛堝湪32bits 騫沖彴涓婏級錛?bytes 錛堝湪64bits騫沖彴涓婏級銆?br />
鍋囪閭g墖鍐呭瓨鐨勫湴鍧涓篶hunk錛岄偅涔堟垜浠彲浠ヨ繖鏍峰仛錛?  

 1 obj* current_obj, *next_obj;
 2
 next_obj = (obj*)chunk;
 3 for (int i = 0; ; i++) {
 4     current_obj = next_obj;
 5     next_obj = (obj*)((char*)next_obj + m);
 6     if (n - 1 == i) {
 7         current_obj -> free_list_link = 0;
 8         break;
 9     } else {
10         current_obj -> free_list_link = next_obj;
11     }
12 }
13 


Zero Lee 2012-06-16 18:38 鍙戣〃璇勮
]]>
[杞澆] STL allocator鐨勪粙緇嶅拰涓涓熀浜巑alloc/free鐨刟llocator鐨勭畝鍗曞疄鐜?/title><link>http://www.shnenglu.com/zerolee/archive/2012/06/16/179042.html</link><dc:creator>Zero Lee</dc:creator><author>Zero Lee</author><pubDate>Sat, 16 Jun 2012 04:13:00 GMT</pubDate><guid>http://www.shnenglu.com/zerolee/archive/2012/06/16/179042.html</guid><wfw:comment>http://www.shnenglu.com/zerolee/comments/179042.html</wfw:comment><comments>http://www.shnenglu.com/zerolee/archive/2012/06/16/179042.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/zerolee/comments/commentRss/179042.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/zerolee/services/trackbacks/179042.html</trackback:ping><description><![CDATA[     鎽樿: Allocators are one of the most mysterious parts of the C++ Standard library. Allocators are rarely used explicitly; the Standard doesn't make it clear when they should ever be used. Today's allocators...  <a href='http://www.shnenglu.com/zerolee/archive/2012/06/16/179042.html'>闃呰鍏ㄦ枃</a><img src ="http://www.shnenglu.com/zerolee/aggbug/179042.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/zerolee/" target="_blank">Zero Lee</a> 2012-06-16 12:13 <a href="http://www.shnenglu.com/zerolee/archive/2012/06/16/179042.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>Memory Poolhttp://www.shnenglu.com/zerolee/archive/2012/06/16/179032.htmlZero LeeZero LeeSat, 16 Jun 2012 02:40:00 GMThttp://www.shnenglu.com/zerolee/archive/2012/06/16/179032.htmlhttp://www.shnenglu.com/zerolee/comments/179032.htmlhttp://www.shnenglu.com/zerolee/archive/2012/06/16/179032.html#Feedback0http://www.shnenglu.com/zerolee/comments/commentRss/179032.htmlhttp://www.shnenglu.com/zerolee/services/trackbacks/179032.html

Zero Lee 2012-06-16 10:40 鍙戣〃璇勮
]]>
[杞琞澶氱嚎紼嬮槦鍒楃殑綆楁硶浼樺寲http://www.shnenglu.com/zerolee/archive/2012/06/05/177651.htmlZero LeeZero LeeTue, 05 Jun 2012 06:26:00 GMThttp://www.shnenglu.com/zerolee/archive/2012/06/05/177651.htmlhttp://www.shnenglu.com/zerolee/comments/177651.htmlhttp://www.shnenglu.com/zerolee/archive/2012/06/05/177651.html#Feedback0http://www.shnenglu.com/zerolee/comments/commentRss/177651.htmlhttp://www.shnenglu.com/zerolee/services/trackbacks/177651.html闃呰鍏ㄦ枃

Zero Lee 2012-06-05 14:26 鍙戣〃璇勮
]]>
姹備竴涓鏁存暟鐨勫鉤鏂規牴紼嬪簭瀹炵幇http://www.shnenglu.com/zerolee/archive/2011/10/19/158661.htmlZero LeeZero LeeWed, 19 Oct 2011 01:37:00 GMThttp://www.shnenglu.com/zerolee/archive/2011/10/19/158661.htmlhttp://www.shnenglu.com/zerolee/comments/158661.htmlhttp://www.shnenglu.com/zerolee/archive/2011/10/19/158661.html#Feedback0http://www.shnenglu.com/zerolee/comments/commentRss/158661.htmlhttp://www.shnenglu.com/zerolee/services/trackbacks/158661.html閲囩敤鍔犳硶閫掑鐨勬柟寮忔潵浠f浛涔樻硶涓嶯榪涜姣旇緝錛岄掑鏄寜鐓х瓑宸暟鍒楃殑鏂瑰紡銆?br />
 1 int square(int n)
 2 {
 3     int tmp = 0;
 4     for (int i = 1; i < n; i++) {
 5         tmp += 2*(i-1)+1;
 6         if (tmp == n)
 7             return i;
 8         continue;
 9     }
10     if (n!=0) {
11         printf("no integer sqare found!\n");
12         tmp = -1;
13     }
14     return tmp;
15 }
16 


Zero Lee 2011-10-19 09:37 鍙戣〃璇勮
]]>
涓緇勬暟鐨勫叏鎺掑垪鍜岀粍鍚堢▼搴忓疄鐜?/title><link>http://www.shnenglu.com/zerolee/archive/2011/10/19/158660.html</link><dc:creator>Zero Lee</dc:creator><author>Zero Lee</author><pubDate>Wed, 19 Oct 2011 01:34:00 GMT</pubDate><guid>http://www.shnenglu.com/zerolee/archive/2011/10/19/158660.html</guid><wfw:comment>http://www.shnenglu.com/zerolee/comments/158660.html</wfw:comment><comments>http://www.shnenglu.com/zerolee/archive/2011/10/19/158660.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/zerolee/comments/commentRss/158660.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/zerolee/services/trackbacks/158660.html</trackback:ping><description><![CDATA[鏄劇ず涓緇勬暟鐨勫叏鎺掑垪鍜岀粍鍚堢▼搴忥細 <div style="font-size: 13px; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #cccccc; border-right-color: #cccccc; border-bottom-color: #cccccc; border-left-color: #cccccc; padding-right: 5px; padding-bottom: 4px; padding-left: 4px; padding-top: 4px; width: 98%; word-break: break-all; background-color: #eeeeee; "><!--<br /> <br /> Code highlighting produced by Actipro CodeHighlighter (freeware)<br /> http://www.CodeHighlighter.com/<br /> <br /> --><span style="color: #008080; "> 1</span> <span style="color: #0000FF; ">void</span><span style="color: #000000; "> print(</span><span style="color: #0000FF; ">const</span><span style="color: #000000; "> std::vector</span><span style="color: #000000; "><</span><span style="color: #0000FF; ">int</span><span style="color: #000000; ">>&</span><span style="color: #000000; "> s)<br /> </span><span style="color: #008080; "> 2</span> <span style="color: #000000; ">{<br /> </span><span style="color: #008080; "> 3</span> <span style="color: #000000; ">    </span><span style="color: #0000FF; ">static</span><span style="color: #000000; "> </span><span style="color: #0000FF; ">int</span><span style="color: #000000; "> n </span><span style="color: #000000; ">=</span><span style="color: #000000; "> </span><span style="color: #000000; ">1</span><span style="color: #000000; ">;<br /> </span><span style="color: #008080; "> 4</span> <span style="color: #000000; ">    printf(</span><span style="color: #000000; ">"</span><span style="color: #000000; ">%d:</span><span style="color: #000000; ">"</span><span style="color: #000000; ">, n</span><span style="color: #000000; ">++</span><span style="color: #000000; ">);<br /> </span><span style="color: #008080; "> 5</span> <span style="color: #000000; ">    printf(</span><span style="color: #000000; ">"</span><span style="color: #000000; ">[</span><span style="color: #000000; ">"</span><span style="color: #000000; ">);<br /> </span><span style="color: #008080; "> 6</span> <span style="color: #000000; ">    </span><span style="color: #0000FF; ">for</span><span style="color: #000000; "> (</span><span style="color: #0000FF; ">int</span><span style="color: #000000; "> i </span><span style="color: #000000; ">=</span><span style="color: #000000; "> </span><span style="color: #000000; ">0</span><span style="color: #000000; ">; i </span><span style="color: #000000; "><</span><span style="color: #000000; "> s.size(); i</span><span style="color: #000000; ">++</span><span style="color: #000000; ">)<br /> </span><span style="color: #008080; "> 7</span> <span style="color: #000000; ">        printf(</span><span style="color: #000000; ">"</span><span style="color: #000000; "> %d </span><span style="color: #000000; ">"</span><span style="color: #000000; ">, s[i]);<br /> </span><span style="color: #008080; "> 8</span> <span style="color: #000000; ">    printf(</span><span style="color: #000000; ">"</span><span style="color: #000000; ">]\n</span><span style="color: #000000; ">"</span><span style="color: #000000; ">);<br /> </span><span style="color: #008080; "> 9</span> <span style="color: #000000; ">}<br /> </span><span style="color: #008080; ">10</span> <span style="color: #000000; "><br /> </span><span style="color: #008080; ">11</span> <span style="color: #000000; "></span><span style="color: #0000FF; ">void</span><span style="color: #000000; "> permutation(std::vector</span><span style="color: #000000; "><</span><span style="color: #0000FF; ">int</span><span style="color: #000000; ">>&</span><span style="color: #000000; "> v, </span><span style="color: #0000FF; ">int</span><span style="color: #000000; "> beg, </span><span style="color: #0000FF; ">int</span><span style="color: #000000; "> end)<br /> </span><span style="color: #008080; ">12</span> <span style="color: #000000; ">{<br /> </span><span style="color: #008080; ">13</span> <span style="color: #000000; ">    </span><span style="color: #0000FF; ">if</span><span style="color: #000000; "> (beg </span><span style="color: #000000; ">></span><span style="color: #000000; "> end) {<br /> </span><span style="color: #008080; ">14</span> <span style="color: #000000; ">        print(v);<br /> </span><span style="color: #008080; ">15</span> <span style="color: #000000; ">        </span><span style="color: #0000FF; ">return</span><span style="color: #000000; ">;<br /> </span><span style="color: #008080; ">16</span> <span style="color: #000000; ">    }<br /> </span><span style="color: #008080; ">17</span> <span style="color: #000000; ">    </span><span style="color: #0000FF; ">for</span><span style="color: #000000; "> (</span><span style="color: #0000FF; ">int</span><span style="color: #000000; "> i </span><span style="color: #000000; ">=</span><span style="color: #000000; "> beg; i </span><span style="color: #000000; "><=</span><span style="color: #000000; "> end; i</span><span style="color: #000000; ">++</span><span style="color: #000000; ">) {<br /> </span><span style="color: #008080; ">18</span> <span style="color: #000000; ">        std::swap(v[i], v[beg]);<br /> </span><span style="color: #008080; ">19</span> <span style="color: #000000; ">        permutation(v, beg</span><span style="color: #000000; ">+</span><span style="color: #000000; ">1</span><span style="color: #000000; ">, end); </span><span style="color: #008000; ">//</span><span style="color: #008000; "> pleate note, here always beg+1, not i+1</span><span style="color: #008000; "><br /> </span><span style="color: #008080; ">20</span> <span style="color: #008000; "></span><span style="color: #000000; ">        std::swap(v[i], v[beg]);<br /> </span><span style="color: #008080; ">21</span> <span style="color: #000000; ">    }<br /> </span><span style="color: #008080; ">22</span> <span style="color: #000000; ">}<br /> </span><span style="color: #008080; ">23</span> <span style="color: #000000; "><br /> </span><span style="color: #008080; ">24</span> <span style="color: #000000; "></span><span style="color: #0000FF; ">void</span><span style="color: #000000; "> pm(std::vector</span><span style="color: #000000; "><</span><span style="color: #0000FF; ">int</span><span style="color: #000000; ">>&</span><span style="color: #000000; "> v)<br /> </span><span style="color: #008080; ">25</span> <span style="color: #000000; ">{<br /> </span><span style="color: #008080; ">26</span> <span style="color: #000000; ">    std::copy(v.begin(), v.end(), std::ostream_iterator</span><span style="color: #000000; "><</span><span style="color: #0000FF; ">int</span><span style="color: #000000; ">></span><span style="color: #000000; ">(std::cout, </span><span style="color: #000000; ">"</span><span style="color: #000000; "> </span><span style="color: #000000; ">"</span><span style="color: #000000; ">));<br /> </span><span style="color: #008080; ">27</span> <span style="color: #000000; ">    printf(</span><span style="color: #000000; ">"</span><span style="color: #000000; ">\nfull permulation are:\n</span><span style="color: #000000; ">"</span><span style="color: #000000; ">);<br /> </span><span style="color: #008080; ">28</span> <span style="color: #000000; ">    permutation(v, </span><span style="color: #000000; ">0</span><span style="color: #000000; ">, v.size()</span><span style="color: #000000; ">-</span><span style="color: #000000; ">1</span><span style="color: #000000; ">);<br /> </span><span style="color: #008080; ">29</span> <span style="color: #000000; ">}<br /> </span><span style="color: #008080; ">30</span> <span style="color: #000000; "><br /> </span><span style="color: #008080; ">31</span> <span style="color: #000000; "></span><span style="color: #0000FF; ">void</span><span style="color: #000000; "> print(</span><span style="color: #0000FF; ">const</span><span style="color: #000000; "> std::vector</span><span style="color: #000000; "><</span><span style="color: #0000FF; ">int</span><span style="color: #000000; ">>&</span><span style="color: #000000; "> v, </span><span style="color: #0000FF; ">int</span><span style="color: #000000; "> beg, </span><span style="color: #0000FF; ">int</span><span style="color: #000000; "> end)<br /> </span><span style="color: #008080; ">32</span> <span style="color: #000000; ">{<br /> </span><span style="color: #008080; ">33</span> <span style="color: #000000; ">    </span><span style="color: #0000FF; ">static</span><span style="color: #000000; "> </span><span style="color: #0000FF; ">int</span><span style="color: #000000; "> n </span><span style="color: #000000; ">=</span><span style="color: #000000; "> </span><span style="color: #000000; ">1</span><span style="color: #000000; ">;<br /> </span><span style="color: #008080; ">34</span> <span style="color: #000000; ">    printf(</span><span style="color: #000000; ">"</span><span style="color: #000000; ">%d:</span><span style="color: #000000; ">"</span><span style="color: #000000; ">, n</span><span style="color: #000000; ">++</span><span style="color: #000000; ">);<br /> </span><span style="color: #008080; ">35</span> <span style="color: #000000; ">    printf(</span><span style="color: #000000; ">"</span><span style="color: #000000; ">[</span><span style="color: #000000; ">"</span><span style="color: #000000; ">);<br /> </span><span style="color: #008080; ">36</span> <span style="color: #000000; ">    std::copy(v.begin()</span><span style="color: #000000; ">+</span><span style="color: #000000; ">beg, v.begin()</span><span style="color: #000000; ">+</span><span style="color: #000000; ">end</span><span style="color: #000000; ">+</span><span style="color: #000000; ">1</span><span style="color: #000000; ">, std::ostream_iterator</span><span style="color: #000000; "><</span><span style="color: #0000FF; ">int</span><span style="color: #000000; ">></span><span style="color: #000000; ">(std::cout, </span><span style="color: #000000; ">"</span><span style="color: #000000; "> </span><span style="color: #000000; ">"</span><span style="color: #000000; ">));<br /> </span><span style="color: #008080; ">37</span> <span style="color: #000000; ">    printf(</span><span style="color: #000000; ">"</span><span style="color: #000000; ">]\n</span><span style="color: #000000; ">"</span><span style="color: #000000; ">);<br /> </span><span style="color: #008080; ">38</span> <span style="color: #000000; ">}<br /> </span><span style="color: #008080; ">39</span> <span style="color: #000000; "><br /> </span><span style="color: #008080; ">40</span> <span style="color: #000000; "></span><span style="color: #0000FF; ">void</span><span style="color: #000000; "> fullcombination(std::vector</span><span style="color: #000000; "><</span><span style="color: #0000FF; ">int</span><span style="color: #000000; ">>&</span><span style="color: #000000; "> v)<br /> </span><span style="color: #008080; ">41</span> <span style="color: #000000; ">{<br /> </span><span style="color: #008080; ">42</span> <span style="color: #000000; ">    printf(</span><span style="color: #000000; ">"</span><div style="display: inline-block; "></div>full combination<span style="color: #000000; "> are:\n</span><span style="color: #000000; ">"</span><span style="color: #000000; ">);<br /> </span><span style="color: #008080; ">43</span> <span style="color: #000000; ">    </span><span style="color: #0000FF; ">for</span><span style="color: #000000; "> (unsigned </span><span style="color: #0000FF; ">int</span><span style="color: #000000; "> i </span><span style="color: #000000; ">=</span><span style="color: #000000; "> </span><span style="color: #000000; ">0</span><span style="color: #000000; ">; i </span><span style="color: #000000; "><</span><span style="color: #000000; "> v.size(); i</span><span style="color: #000000; ">++</span><span style="color: #000000; ">) {<br /> </span><span style="color: #008080; ">44</span> <span style="color: #000000; ">        print(v, i, i);<br /> </span><span style="color: #008080; ">45</span> <span style="color: #000000; ">        </span><span style="color: #0000FF; ">for</span><span style="color: #000000; "> (unsigned </span><span style="color: #0000FF; ">int</span><span style="color: #000000; "> j </span><span style="color: #000000; ">=</span><span style="color: #000000; "> i</span><span style="color: #000000; ">+</span><span style="color: #000000; ">1</span><span style="color: #000000; ">; j </span><span style="color: #000000; "><</span><span style="color: #000000; "> v.size(); j</span><span style="color: #000000; ">++</span><span style="color: #000000; ">) {<br /> </span><span style="color: #008080; ">46</span> <span style="color: #000000; ">            </span><span style="color: #0000FF; ">for</span><span style="color: #000000; "> (</span><span style="color: #0000FF; ">int</span><span style="color: #000000; "> k </span><span style="color: #000000; ">=</span><span style="color: #000000; "> </span><span style="color: #000000; ">0</span><span style="color: #000000; ">; k </span><span style="color: #000000; "><</span><span style="color: #000000; "> v.size()</span><span style="color: #000000; ">-</span><span style="color: #000000; ">j; k</span><span style="color: #000000; ">++</span><span style="color: #000000; ">) {<br /> </span><span style="color: #008080; ">47</span> <span style="color: #000000; ">                std::swap(v[j</span><span style="color: #000000; ">+</span><span style="color: #000000; ">k], v[j]);<br /> </span><span style="color: #008080; ">48</span> <span style="color: #000000; ">                print(v, i, j);<br /> </span><span style="color: #008080; ">49</span> <span style="color: #000000; ">                std::swap(v[j</span><span style="color: #000000; ">+</span><span style="color: #000000; ">k], v[j]);<br /> </span><span style="color: #008080; ">50</span> <span style="color: #000000; ">            }<br /> </span><span style="color: #008080; ">51</span> <span style="color: #000000; ">        }<br /> </span><span style="color: #008080; ">52</span> <span style="color: #000000; ">    }<br /> </span><span style="color: #008080; ">53</span> <span style="color: #000000; ">}<br /> </span><span style="color: #008080; ">54</span> <span style="color: #000000; "></span></div><img src ="http://www.shnenglu.com/zerolee/aggbug/158660.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/zerolee/" target="_blank">Zero Lee</a> 2011-10-19 09:34 <a href="http://www.shnenglu.com/zerolee/archive/2011/10/19/158660.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>Generating Permutationshttp://www.shnenglu.com/zerolee/archive/2011/09/21/156428.htmlZero LeeZero LeeWed, 21 Sep 2011 07:22:00 GMThttp://www.shnenglu.com/zerolee/archive/2011/09/21/156428.htmlhttp://www.shnenglu.com/zerolee/comments/156428.htmlhttp://www.shnenglu.com/zerolee/archive/2011/09/21/156428.html#Feedback0http://www.shnenglu.com/zerolee/comments/commentRss/156428.htmlhttp://www.shnenglu.com/zerolee/services/trackbacks/156428.htmlA permutation can be obtained by selecting an element in the given set and recursively permuting the remaining elements.

 { ai,P(a1,...,ai-1,ai+1,...,aN) if N > 1 P(a1,...,aN) = aN if N = 1


 --|--|--|-| |a|b-|c-d-| a|------------b------------c-------------d --|--|--|-| ---|-|--|--| ---|--|-|--| --|--|--|-| |-|b-|c-d-| |a-|-|c-|d-| |a-|b-|-|d-| |a|b-|c-|-|

At each stage of the permutation process, the given set of elements consists of two parts: a subset of values that already have been processed, and a subset that still needs to be processed. This logical seperation can be physically realized by exchanging, in the i’th step, the i’th value with the value being chosen at that stage. That approaches leaves the first subset in the first i locations of the outcome.

 --|--|--|-| |a|b-|c-d-| --|--|------------|--------------------------|--|-| a||b |c d | |b a |c |d | |c||b |a|d | |d|b |c |a| -----|--------------------------|---- ----------- --|--|--|-| ---|-|--|--| ---|--|-|--| b-|a-|c-d-| |b-|c|a-|d-| |b-|d-|c|a-| ---|--|------------|--|-| |b-|c-a-|d-| b-|c-|d-|a| | b-|c-|d-|a| |-|--|--|-|
permute(i) 
   if i == N  output A[N] 
   else 
      for j = i to N do 
         swap(A[i], A[j]) 
         permute(i+1) 
         swap(A[i], A[j]) 


Zero Lee 2011-09-21 15:22 鍙戣〃璇勮
]]>
Inside The C++ Object Model 闃呰絎旇http://www.shnenglu.com/zerolee/archive/2011/09/19/156212.htmlZero LeeZero LeeMon, 19 Sep 2011 05:18:00 GMThttp://www.shnenglu.com/zerolee/archive/2011/09/19/156212.htmlhttp://www.shnenglu.com/zerolee/comments/156212.htmlhttp://www.shnenglu.com/zerolee/archive/2011/09/19/156212.html#Feedback0http://www.shnenglu.com/zerolee/comments/commentRss/156212.htmlhttp://www.shnenglu.com/zerolee/services/trackbacks/156212.html鏈?縐嶆儏鍐典細瀵艱嚧“緙栬瘧鍣ㄥ繀欏諱負鏈0鏄巆onstructor涔媍lasses鍚堟垚涓涓猟efault constructor“銆侰++ 鏍囧噯鎶婇偅浜涘悎鎴愮墿縐頒負implicit nontrivial default constructors銆傝鍚堟垚鍑烘潵鐨刢onstructor鍙兘婊¤凍緙栬瘧鍣?鑰岄潪紼嬪簭)鐨勯渶瑕併傚畠涔嬫墍浠ヨ兘澶熷畬鎴愪換鍔★紝鏄熺潃“璋冪敤member object 鎴?base class 鐨刣efault constructor“ 鎴栨槸 ”涓烘瘡涓涓猳bject鍒濆鍖栧叾virtual function 鏈哄埗鎴杤irtual base class鏈哄埗“鑰屽畬鎴愩傝嚦浜庢病鏈夊瓨鍦ㄩ偅鍥涚鎯呭喌鑰屽張娌℃湁澹版槑浠諱綍constructor鐨刢lasses錛屾垜浠瀹冧滑鎷ユ湁鐨勬槸implicit trivial default constructors錛屽畠浠疄闄呬笂騫朵笉浼氳鍚堟垚鍑烘潵銆?br />鍦ㄥ悎鎴愬嚭鏉ョ殑default constructor涓紝鍙湁base class subobjects 鍜宮ember class objects浼氳鍒濆鍖栥傛墍鏈夊叾瀹冪殑nonstatic data memeber錛屽鏁存暟銆佹暣鏁版寚閽堛佹暣鏁版暟緇勭瓑絳夐兘涓嶄細琚垵濮嬪寲銆傝繖浜涘垵濮嬪寲鎿嶄綔瀵圭▼搴忚岃█鎴栬鏈夐渶瑕侊紝浣嗗緙栬瘧鍣ㄥ垯騫墮潪蹇呰銆?br />2. The semantics of copy constructor
鏈?縐嶆儏鍐碉紝涓涓猚lass涓嶅睍鐜板嚭"bitwise copy semantics"錛?br />1) 褰揷lass鍐呭惈涓涓猰ember object鑰屽悗鑰呯殑class澹版槑鏈変竴涓猚opy constructor鏃?涓嶈鏄class 璁捐鑰呮槑紜殑澹版槑錛岃繕鏄緙栬瘧鍣ㄥ悎鎴?;
2) 褰揷lass緇ф壙鑷竴涓猙ase class鑰屽悗鑰呭瓨鍦ㄤ竴涓猚opy constructor鏃?鍐嶆寮鴻皟錛屼笉璁烘槸琚槑紜0鏄庤繕鏄鍚堟垚鑰屽緱);
3) 褰揷lass澹版槑浜嗕竴涓垨澶氫釜virtual functions鏃訛紱
4) 褰揷lass媧劇敓鑷竴涓戶鎵夸覆閾撅紝鍏朵腑鏈変竴涓垨澶氫釜virtual base classes鏃躲?br />鍓?縐嶆儏鍐典腑錛岀紪璇戝櫒蹇呴』灝唌ember鎴朾ase class鐨?copy constructors 璋冪敤鎿嶄綔"瀹夋彃鍒拌鍚堟垚鐨刢opy constructor涓?br />




Zero Lee 2011-09-19 13:18 鍙戣〃璇勮
]]>
Inside The C++ Object Model 闃呰絎旇http://www.shnenglu.com/zerolee/archive/2011/09/19/156211.htmlZero LeeZero LeeMon, 19 Sep 2011 05:18:00 GMThttp://www.shnenglu.com/zerolee/archive/2011/09/19/156211.htmlhttp://www.shnenglu.com/zerolee/comments/156211.htmlhttp://www.shnenglu.com/zerolee/archive/2011/09/19/156211.html#Feedback0http://www.shnenglu.com/zerolee/comments/commentRss/156211.htmlhttp://www.shnenglu.com/zerolee/services/trackbacks/156211.html鏈?縐嶆儏鍐典細瀵艱嚧“緙栬瘧鍣ㄥ繀欏諱負鏈0鏄巆onstructor涔媍lasses鍚堟垚涓涓猟efault constructor“銆侰++ 鏍囧噯鎶婇偅浜涘悎鎴愮墿縐頒負implicit nontrivial default constructors銆傝鍚堟垚鍑烘潵鐨刢onstructor鍙兘婊¤凍緙栬瘧鍣?鑰岄潪紼嬪簭)鐨勯渶瑕併傚畠涔嬫墍浠ヨ兘澶熷畬鎴愪換鍔★紝鏄熺潃“璋冪敤member object 鎴?base class 鐨刣efault constructor“ 鎴栨槸 ”涓烘瘡涓涓猳bject鍒濆鍖栧叾virtual function 鏈哄埗鎴杤irtual base class鏈哄埗“鑰屽畬鎴愩傝嚦浜庢病鏈夊瓨鍦ㄩ偅鍥涚鎯呭喌鑰屽張娌℃湁澹版槑浠諱綍constructor鐨刢lasses錛屾垜浠瀹冧滑鎷ユ湁鐨勬槸implicit trivial default constructors錛屽畠浠疄闄呬笂騫朵笉浼氳鍚堟垚鍑烘潵銆?br />鍦ㄥ悎鎴愬嚭鏉ョ殑default constructor涓紝鍙湁base class subobjects 鍜宮ember class objects浼氳鍒濆鍖栥傛墍鏈夊叾瀹冪殑nonstatic data memeber錛屽鏁存暟銆佹暣鏁版寚閽堛佹暣鏁版暟緇勭瓑絳夐兘涓嶄細琚垵濮嬪寲銆傝繖浜涘垵濮嬪寲鎿嶄綔瀵圭▼搴忚岃█鎴栬鏈夐渶瑕侊紝浣嗗緙栬瘧鍣ㄥ垯騫墮潪蹇呰銆?br />






Zero Lee 2011-09-19 13:18 鍙戣〃璇勮
]]>
久久久久久国产a免费观看黄色大片| 久久久久久精品成人免费图片| 精品永久久福利一区二区| 99精品国产99久久久久久97 | 中文字幕一区二区三区久久网站| 久久久久久亚洲Av无码精品专口| 精品一区二区久久| 怡红院日本一道日本久久| 亚洲精品tv久久久久| 色综合久久无码中文字幕| 国产午夜精品理论片久久| 色偷偷88888欧美精品久久久| 精品国产综合区久久久久久 | 久久久免费观成人影院| 亚洲AV无码久久| 久久精品18| 国产精品女同一区二区久久| 精品国产乱码久久久久久呢| 狠狠色丁香婷综合久久| 麻豆亚洲AV永久无码精品久久| 亚洲国产香蕉人人爽成AV片久久| 久久被窝电影亚洲爽爽爽| 国产A三级久久精品| 久久93精品国产91久久综合 | 久久久无码精品亚洲日韩蜜臀浪潮| 99久久国产综合精品网成人影院| 97热久久免费频精品99| 国产成人无码精品久久久性色 | 国产99久久精品一区二区| 波多野结衣AV无码久久一区| 亚洲精品tv久久久久久久久久| 久久久久女教师免费一区| 国产精品久久久久久| 久久久久亚洲AV片无码下载蜜桃| 婷婷综合久久中文字幕蜜桃三电影| 一本久久a久久精品综合香蕉| 久久国产免费| 久久影院亚洲一区| 麻豆久久久9性大片| 久久久一本精品99久久精品88| 亚洲综合熟女久久久30p|