Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

160 lines
5.0 KiB

  1. // numeric standard header
  2. #pragma once
  3. #ifndef _NUMERIC_
  4. #define _NUMERIC_
  5. #include <iterator>
  6. #pragma pack(push,8)
  7. #pragma warning(push,3)
  8. _STD_BEGIN
  9. // TEMPLATE FUNCTION accumulate
  10. template<class _InIt, class _Ty> inline
  11. _Ty accumulate(_InIt _First, _InIt _Last, _Ty _Val)
  12. { // return sum of _Val and all in [_First, _Last)
  13. for (; _First != _Last; ++_First)
  14. _Val = _Val + *_First;
  15. return (_Val);
  16. }
  17. // TEMPLATE FUNCTION accumulate WITH BINOP
  18. template<class _InIt, class _Ty, class _Fn2> inline
  19. _Ty accumulate(_InIt _First, _InIt _Last, _Ty _Val, _Fn2 _Func)
  20. { // return sum of _Val and all in [_First, _Last), using _Func
  21. for (; _First != _Last; ++_First)
  22. _Val = _Func(_Val, *_First);
  23. return (_Val);
  24. }
  25. // TEMPLATE FUNCTION inner_product
  26. template<class _InIt1, class _InIt2, class _Ty> inline
  27. _Ty inner_product(_InIt1 _First1, _InIt1 _Last1, _InIt2 _First2, _Ty _Val)
  28. { // return inner product of sequences
  29. for (; _First1 != _Last1; ++_First1, ++_First2)
  30. _Val = _Val + *_First1 * *_First2;
  31. return (_Val);
  32. }
  33. // TEMPLATE FUNCTION inner_product WITH BINOPS
  34. template<class _InIt1, class _InIt2, class _Ty,
  35. class _Fn21, class _Fn22> inline
  36. _Ty inner_product(_InIt1 _First1, _InIt1 _Last1, _InIt2 _First2, _Ty _Val,
  37. _Fn21 _Func1, _Fn22 _Func2)
  38. { // return inner product of sequences, using _Func1 and _Func2
  39. for (; _First1 != _Last1; ++_First1, ++_First2)
  40. _Val = _Func1(_Val, _Func2(*_First1, *_First2));
  41. return (_Val);
  42. }
  43. // TEMPLATE FUNCTION partial_sum
  44. template<class _InIt, class _OutIt, class _Ty> inline
  45. _OutIt _Partial_sum(_InIt _First, _InIt _Last,
  46. _OutIt _Dest, _Ty *)
  47. { // compute partial sums into _Dest
  48. _Ty _Val = *_First;
  49. for (*_Dest = _Val; ++_First != _Last; *++_Dest = _Val)
  50. _Val = _Val + *_First;
  51. return (++_Dest);
  52. }
  53. template<class _InIt, class _OutIt> inline
  54. _OutIt partial_sum(_InIt _First, _InIt _Last,
  55. _OutIt _Dest)
  56. { // compute partial sums into _Dest
  57. return (_First == _Last ? _Dest
  58. : _Partial_sum(_First, _Last, _Dest, _Val_type(_First)));
  59. }
  60. // TEMPLATE FUNCTION partial_sum WITH BINOP
  61. template<class _InIt, class _OutIt, class _Fn2, class _Ty> inline
  62. _OutIt _Partial_sum(_InIt _First, _InIt _Last,
  63. _OutIt _Dest, _Fn2 _Func, _Ty *)
  64. { // compute partial sums into _Dest, using _Func
  65. _Ty _Val = *_First;
  66. for (*_Dest = _Val; ++_First != _Last; *++_Dest = _Val)
  67. _Val = _Func(_Val, *_First);
  68. return (++_Dest);
  69. }
  70. template<class _InIt, class _OutIt, class _Fn2> inline
  71. _OutIt partial_sum(_InIt _First, _InIt _Last,
  72. _OutIt _Dest, _Fn2 _Func)
  73. { // compute partial sums into _Dest, using _Func
  74. return (_First == _Last ? _Dest
  75. : _Partial_sum(_First, _Last, _Dest, _Func, _Val_type(_First)));
  76. }
  77. // TEMPLATE FUNCTION adjacent_difference
  78. template<class _InIt, class _OutIt, class _Ty> inline
  79. _OutIt _Adjacent_difference(_InIt _First, _InIt _Last,
  80. _OutIt _Dest, _Ty *)
  81. { // compute adjacent differences into _Dest
  82. _Ty _Val = *_First;
  83. for (*_Dest = _Val; ++_First != _Last; )
  84. { // compute another difference
  85. _Ty _Tmp = *_First;
  86. *++_Dest = _Tmp - _Val;
  87. _Val = _Tmp;
  88. }
  89. return (++_Dest);
  90. }
  91. template<class _InIt, class _OutIt> inline
  92. _OutIt adjacent_difference(_InIt _First, _InIt _Last,
  93. _OutIt _Dest)
  94. { // compute adjacent differences into _Dest
  95. return (_First == _Last ? _Dest
  96. : _Adjacent_difference(_First, _Last, _Dest, _Val_type(_First)));
  97. }
  98. // TEMPLATE FUNCTION adjacent_difference WITH BINOP
  99. template<class _InIt, class _OutIt, class _Fn2, class _Ty> inline
  100. _OutIt _Adjacent_difference(_InIt _First, _InIt _Last,
  101. _OutIt _Dest, _Fn2 _Func, _Ty *)
  102. { // compute adjacent differences into _Dest, using _Func
  103. _Ty _Val = *_First;
  104. for (*_Dest = _Val; ++_First != _Last; )
  105. { // compute another difference
  106. _Ty _Tmp = *_First;
  107. *++_Dest = _Func(_Tmp, _Val);
  108. _Val = _Tmp;
  109. }
  110. return (++_Dest);
  111. }
  112. template<class _InIt, class _OutIt, class _Fn2> inline
  113. _OutIt adjacent_difference(_InIt _First, _InIt _Last,
  114. _OutIt _Dest, _Fn2 _Func)
  115. { // compute adjacent differences into _Dest, using _Func
  116. return (_First == _Last ? _Dest : _Adjacent_difference(_First, _Last,
  117. _Dest, _Func, _Val_type(_First)));
  118. }
  119. _STD_END
  120. #pragma warning(pop)
  121. #pragma pack(pop)
  122. #endif /* _NUMERIC_ */
  123. /*
  124. * Copyright (c) 1992-2001 by P.J. Plauger. ALL RIGHTS RESERVED.
  125. * Consult your license regarding permissions and restrictions.
  126. */
  127. /*
  128. * This file is derived from software bearing the following
  129. * restrictions:
  130. *
  131. * Copyright (c) 1994
  132. * Hewlett-Packard Company
  133. *
  134. * Permission to use, copy, modify, distribute and sell this
  135. * software and its documentation for any purpose is hereby
  136. * granted without fee, provided that the above copyright notice
  137. * appear in all copies and that both that copyright notice and
  138. * this permission notice appear in supporting documentation.
  139. * Hewlett-Packard Company makes no representations about the
  140. * suitability of this software for any purpose. It is provided
  141. * "as is" without express or implied warranty.
  142. V3.10:0009 */