vector_8hpp_source.tex 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. \hypertarget{vector_8hpp_source}{}\doxysection{vector.\+hpp}
  2. \label{vector_8hpp_source}\index{src/vector.hpp@{src/vector.hpp}}
  3. \mbox{\hyperlink{vector_8hpp}{Go to the documentation of this file.}}
  4. \begin{DoxyCode}{0}
  5. \DoxyCodeLine{1 \textcolor{preprocessor}{\#ifndef VECTOR\_HPP}}
  6. \DoxyCodeLine{2 \textcolor{preprocessor}{\#define VECTOR\_HPP}}
  7. \DoxyCodeLine{3 }
  8. \DoxyCodeLine{4 \textcolor{preprocessor}{\#include <iostream>}}
  9. \DoxyCodeLine{5 \textcolor{preprocessor}{\#include "{}\mbox{\hyperlink{debug_8hpp}{debug.hpp}}"{}}}
  10. \DoxyCodeLine{6 }
  11. \DoxyCodeLine{7 \textcolor{keyword}{using namespace }std;}
  12. \DoxyCodeLine{8 }
  13. \DoxyCodeLine{9 \textcolor{keyword}{using} \mbox{\hyperlink{vector_8hpp_a4b04262b81aa7d31eb5d2f607e2a35de}{Real}} = double;\textcolor{comment}{//float;}}
  14. \DoxyCodeLine{10 }
  15. \DoxyCodeLine{11 \textcolor{preprocessor}{\#ifdef DEBUG}}
  16. \DoxyCodeLine{12 \textcolor{keyword}{struct }\mbox{\hyperlink{vector_8hpp_ab9855a300a7759f4c0f85067d44e4c38}{Vector}}\{}
  17. \DoxyCodeLine{13 \textcolor{keywordtype}{size\_t} n;}
  18. \DoxyCodeLine{14 \mbox{\hyperlink{vector_8hpp_a4b04262b81aa7d31eb5d2f607e2a35de}{Real}}* data;}
  19. \DoxyCodeLine{15 \mbox{\hyperlink{vector_8hpp_a4b04262b81aa7d31eb5d2f607e2a35de}{Real}}\& operator[](\textcolor{keywordtype}{size\_t} i);}
  20. \DoxyCodeLine{16 \};}
  21. \DoxyCodeLine{17 }
  22. \DoxyCodeLine{18 \textcolor{keyword}{inline} \mbox{\hyperlink{vector_8hpp_a4b04262b81aa7d31eb5d2f607e2a35de}{Real}}\&}
  23. \DoxyCodeLine{19 Vector::operator[](\textcolor{keywordtype}{size\_t} i)\{}
  24. \DoxyCodeLine{20 \mbox{\hyperlink{debug_8hpp_a3153a272f18d0f805028fce7e4337b53}{assert}}(i<n);}
  25. \DoxyCodeLine{21 \textcolor{keywordflow}{return} data[i];}
  26. \DoxyCodeLine{22 \}}
  27. \DoxyCodeLine{23 }
  28. \DoxyCodeLine{24 \textcolor{keyword}{inline} \mbox{\hyperlink{vector_8hpp_ab9855a300a7759f4c0f85067d44e4c38}{Vector}}}
  29. \DoxyCodeLine{25 \mbox{\hyperlink{vector_8hpp_a624100980bbf31adef9cc6bfd6e89738}{init\_vector}}(\textcolor{keywordtype}{size\_t} n)\{}
  30. \DoxyCodeLine{26 \mbox{\hyperlink{vector_8hpp_ab9855a300a7759f4c0f85067d44e4c38}{Vector}} v;}
  31. \DoxyCodeLine{27 v.n=n;}
  32. \DoxyCodeLine{28 v.data=\textcolor{keyword}{new} \mbox{\hyperlink{vector_8hpp_a4b04262b81aa7d31eb5d2f607e2a35de}{Real}}[n];}
  33. \DoxyCodeLine{29 \textcolor{keywordflow}{return} v;}
  34. \DoxyCodeLine{30 \}}
  35. \DoxyCodeLine{31 }
  36. \DoxyCodeLine{32 \textcolor{keyword}{inline} \textcolor{keywordtype}{void}}
  37. \DoxyCodeLine{33 \mbox{\hyperlink{vector_8hpp_a34a7c651953c188bf41e94dee669ad70}{delete\_vector}}(\mbox{\hyperlink{vector_8hpp_ab9855a300a7759f4c0f85067d44e4c38}{Vector}} v)\{}
  38. \DoxyCodeLine{34 \textcolor{keyword}{delete}[] v.data;}
  39. \DoxyCodeLine{35 \}}
  40. \DoxyCodeLine{36 }
  41. \DoxyCodeLine{37 \textcolor{keyword}{inline} \textcolor{keywordtype}{bool}}
  42. \DoxyCodeLine{38 is\_null(\mbox{\hyperlink{vector_8hpp_ab9855a300a7759f4c0f85067d44e4c38}{Vector}} v)\{}
  43. \DoxyCodeLine{39 \textcolor{keywordflow}{return} v.n==0;}
  44. \DoxyCodeLine{40 \}}
  45. \DoxyCodeLine{41 }
  46. \DoxyCodeLine{42 \textcolor{keyword}{static} \textcolor{keyword}{const} \mbox{\hyperlink{vector_8hpp_ab9855a300a7759f4c0f85067d44e4c38}{Vector}} NullVector=\{0,\textcolor{keyword}{nullptr}\};}
  47. \DoxyCodeLine{43 }
  48. \DoxyCodeLine{44 \textcolor{preprocessor}{\#else}}
  49. \DoxyCodeLine{45 \textcolor{keyword}{using} \mbox{\hyperlink{vector_8hpp_ab9855a300a7759f4c0f85067d44e4c38}{Vector}}=\mbox{\hyperlink{vector_8hpp_a4b04262b81aa7d31eb5d2f607e2a35de}{Real}}*;}
  50. \DoxyCodeLine{46 }
  51. \DoxyCodeLine{47 \textcolor{keyword}{inline} \mbox{\hyperlink{vector_8hpp_ab9855a300a7759f4c0f85067d44e4c38}{Vector}}}
  52. \DoxyCodeLine{48 \mbox{\hyperlink{vector_8hpp_a624100980bbf31adef9cc6bfd6e89738}{init\_vector}}(\textcolor{keywordtype}{size\_t} n)\{}
  53. \DoxyCodeLine{49 \textcolor{keywordflow}{return} \textcolor{keyword}{new} \mbox{\hyperlink{vector_8hpp_a4b04262b81aa7d31eb5d2f607e2a35de}{Real}}[n];}
  54. \DoxyCodeLine{50 \}}
  55. \DoxyCodeLine{51 }
  56. \DoxyCodeLine{52 \textcolor{keyword}{inline} \textcolor{keywordtype}{void}}
  57. \DoxyCodeLine{53 \mbox{\hyperlink{vector_8hpp_a34a7c651953c188bf41e94dee669ad70}{delete\_vector}}(\mbox{\hyperlink{vector_8hpp_ab9855a300a7759f4c0f85067d44e4c38}{Vector}} v)\{}
  58. \DoxyCodeLine{54 \textcolor{keyword}{delete}[] v;}
  59. \DoxyCodeLine{55 \}}
  60. \DoxyCodeLine{56 \textcolor{preprocessor}{\#endif}}
  61. \DoxyCodeLine{57 }
  62. \DoxyCodeLine{58 \textcolor{keyword}{inline} \textcolor{keywordtype}{void}}
  63. \DoxyCodeLine{59 \mbox{\hyperlink{vector_8hpp_a01121fb497c32a2fc0deee30071180ff}{display}}(\mbox{\hyperlink{vector_8hpp_ab9855a300a7759f4c0f85067d44e4c38}{Vector}} v,\textcolor{keywordtype}{size\_t} n)\{}
  64. \DoxyCodeLine{60 \textcolor{keywordflow}{if}(n==0)\{}
  65. \DoxyCodeLine{61 cout<<\textcolor{stringliteral}{"{}[]"{}}<<endl;}
  66. \DoxyCodeLine{62 \textcolor{keywordflow}{return};}
  67. \DoxyCodeLine{63 \}}
  68. \DoxyCodeLine{64 cout<<\textcolor{charliteral}{'['}<<v[0];}
  69. \DoxyCodeLine{65 \textcolor{keywordflow}{for}(\textcolor{keywordtype}{size\_t} i=1;i<n;++i)\{}
  70. \DoxyCodeLine{66 cout<<\textcolor{charliteral}{','}<<v[i];}
  71. \DoxyCodeLine{67 \}}
  72. \DoxyCodeLine{68 cout<<\textcolor{charliteral}{']'}<<endl;}
  73. \DoxyCodeLine{69 \}}
  74. \DoxyCodeLine{70 }
  75. \DoxyCodeLine{71 \textcolor{keyword}{inline} \textcolor{keywordtype}{size\_t}}
  76. \DoxyCodeLine{72 \mbox{\hyperlink{vector_8hpp_a2edc1ce8353b41e8b9120d90e76c9481}{argmax}}(\mbox{\hyperlink{vector_8hpp_ab9855a300a7759f4c0f85067d44e4c38}{Vector}} v,\textcolor{keywordtype}{size\_t} n)\{}
  77. \DoxyCodeLine{73 \mbox{\hyperlink{debug_8hpp_a3153a272f18d0f805028fce7e4337b53}{assert}}(n>0);}
  78. \DoxyCodeLine{74 \textcolor{keywordtype}{size\_t} imax=0;}
  79. \DoxyCodeLine{75 \mbox{\hyperlink{vector_8hpp_a4b04262b81aa7d31eb5d2f607e2a35de}{Real}} vmax=v[0];}
  80. \DoxyCodeLine{76 \textcolor{keywordflow}{for}(\textcolor{keywordtype}{size\_t} i=1;i<n;++i)\{}
  81. \DoxyCodeLine{77 \textcolor{keywordflow}{if}(v[i]>vmax)\{}
  82. \DoxyCodeLine{78 vmax=v[i];}
  83. \DoxyCodeLine{79 imax=i;}
  84. \DoxyCodeLine{80 \}}
  85. \DoxyCodeLine{81 \}}
  86. \DoxyCodeLine{82 \textcolor{keywordflow}{return} imax;}
  87. \DoxyCodeLine{83 \}}
  88. \DoxyCodeLine{84 }
  89. \DoxyCodeLine{85 \textcolor{keyword}{inline} \textcolor{keywordtype}{size\_t}}
  90. \DoxyCodeLine{86 \mbox{\hyperlink{vector_8hpp_a8a3da36f32f258d0fcd5c8453fcc9c58}{indice2}}(\textcolor{keywordtype}{size\_t} i,\textcolor{keywordtype}{size\_t} j,\textcolor{keywordtype}{size\_t} nj)\{}
  91. \DoxyCodeLine{87 \textcolor{keywordflow}{return} i*nj+j;}
  92. \DoxyCodeLine{88 \}}
  93. \DoxyCodeLine{89 }
  94. \DoxyCodeLine{90 \textcolor{keyword}{inline} \textcolor{keywordtype}{size\_t}}
  95. \DoxyCodeLine{91 \mbox{\hyperlink{vector_8hpp_a6df97fe6a0623e6b4bac1ba311a0a9de}{indice3}}(\textcolor{keywordtype}{size\_t} i,\textcolor{keywordtype}{size\_t} j,\textcolor{keywordtype}{size\_t} k,\textcolor{keywordtype}{size\_t} nj,\textcolor{keywordtype}{size\_t} nk)\{}
  96. \DoxyCodeLine{92 \textcolor{keywordflow}{return} (i*nj+j)*nk+k;}
  97. \DoxyCodeLine{93 \}}
  98. \DoxyCodeLine{94 }
  99. \DoxyCodeLine{95 \textcolor{keyword}{inline} \textcolor{keywordtype}{size\_t}}
  100. \DoxyCodeLine{96 \mbox{\hyperlink{vector_8hpp_a04bfed1c3222805726b019f3bbe185bc}{indice4}}(\textcolor{keywordtype}{size\_t} i,\textcolor{keywordtype}{size\_t} j,\textcolor{keywordtype}{size\_t} k,\textcolor{keywordtype}{size\_t} l,\textcolor{keywordtype}{size\_t} nj,\textcolor{keywordtype}{size\_t} nk,\textcolor{keywordtype}{size\_t} nl)\{}
  101. \DoxyCodeLine{97 \textcolor{keywordflow}{return} ((i*nj+j)*nk+k)*nl+l;}
  102. \DoxyCodeLine{98 \}}
  103. \DoxyCodeLine{99 }
  104. \DoxyCodeLine{100 \textcolor{preprocessor}{\#endif}}
  105. \end{DoxyCode}