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.

112 lines
3.6 KiB

  1. // numeric standard header
  2. #ifndef _NUMERIC_
  3. #define _NUMERIC_
  4. #include <iterator>
  5. #ifdef _MSC_VER
  6. #pragma pack(push,8)
  7. #endif /* _MSC_VER */
  8. _STD_BEGIN
  9. // TEMPLATE FUNCTION accumulate
  10. template<class _II, class _Ty> inline
  11. _Ty accumulate(_II _F, _II _L, _Ty _V)
  12. {for (; _F != _L; ++_F)
  13. _V = _V + *_F;
  14. return (_V); }
  15. // TEMPLATE FUNCTION accumulate WITH BINOP
  16. template<class _II, class _Ty, class _Bop> inline
  17. _Ty accumulate(_II _F, _II _L, _Ty _V, _Bop _B)
  18. {for (; _F != _L; ++_F)
  19. _V = _B(_V, *_F);
  20. return (_V); }
  21. // TEMPLATE FUNCTION inner_product
  22. template<class _II1, class _II2, class _Ty> inline
  23. _Ty inner_product(_II1 _F, _II1 _L, _II2 _X, _Ty _V)
  24. {for (; _F != _L; ++_F, ++_X)
  25. _V = _V + *_F * *_X;
  26. return (_V); }
  27. // TEMPLATE FUNCTION inner_product WITH BINOPS
  28. template<class _II1, class _II2, class _Ty,
  29. class _Bop1, class _Bop2> inline
  30. _Ty inner_product(_II1 _F, _II1 _L, _II2 _X, _Ty _V,
  31. _Bop1 _B1, _Bop2 _B2)
  32. {for (; _F != _L; ++_F, ++_X)
  33. _V = _B1(_V, _B2(*_F, *_X));
  34. return (_V); }
  35. // TEMPLATE FUNCTION partial_sum
  36. template<class _II, class _OI> inline
  37. _OI partial_sum(_II _F, _II _L, _OI _X)
  38. {return (_F == _L ? _X
  39. : _Partial_sum(_F, _L, _X, _Val_type(_F))); }
  40. template<class _II, class _OI, class _Ty> inline
  41. _OI _Partial_sum(_II _F, _II _L, _OI _X, _Ty *)
  42. {_Ty _V = *_F;
  43. for (*_X = _V; ++_F != _L; *++_X = _V)
  44. _V = _V + *_F;
  45. return (++_X); }
  46. // TEMPLATE FUNCTION partial_sum WITH BINOP
  47. template<class _II, class _OI, class _Bop> inline
  48. _OI partial_sum(_II _F, _II _L, _OI _X, _Bop _B)
  49. {return (_F == _L ? _X
  50. : _Partial_sum(_F, _L, _X, _B, _Val_type(_F))); }
  51. template<class _II, class _OI, class _Bop, class _Ty> inline
  52. _OI _Partial_sum(_II _F, _II _L, _OI _X, _Bop _B, _Ty *)
  53. {_Ty _V = *_F;
  54. for (*_X = _V; ++_F != _L; *++_X = _V)
  55. _V = _B(_V, *_F);
  56. return (++_X); }
  57. // TEMPLATE FUNCTION adjacent_difference
  58. template<class _II, class _OI> inline
  59. _OI adjacent_difference(_II _F, _II _L, _OI _X)
  60. {return (_F == _L ? _X
  61. : _Adjacent_difference(_F, _L, _X, _Val_type(_F))); }
  62. template<class _II, class _OI, class _Ty> inline
  63. _OI _Adjacent_difference(_II _F, _II _L, _OI _X, _Ty *)
  64. {_Ty _V = *_F;
  65. for (*_X = _V; ++_F != _L; )
  66. {_Ty _Tmp = *_F;
  67. *++_X = _Tmp - _V;
  68. _V = _Tmp; }
  69. return (++_X); }
  70. // TEMPLATE FUNCTION adjacent_difference WITH BINOP
  71. template<class _II, class _OI, class _Bop> inline
  72. _OI adjacent_difference(_II _F, _II _L, _OI _X, _Bop _B)
  73. {return (_F == _L ? _X
  74. : _Adjacent_difference(_F, _L, _X, _B, _Val_type(_F))); }
  75. template<class _II, class _OI, class _Bop, class _Ty> inline
  76. _OI _Adjacent_difference(_II _F, _II _L, _OI _X,
  77. _Bop _B, _Ty *)
  78. {_Ty _V = *_F;
  79. for (*_X = _V; ++_F != _L; )
  80. {_Ty _Tmp = *_F;
  81. *++_X = _B(_Tmp, _V);
  82. _V = _Tmp; }
  83. return (++_X); }
  84. _STD_END
  85. #ifdef _MSC_VER
  86. #pragma pack(pop)
  87. #endif /* _MSC_VER */
  88. #endif /* _NUMERIC_ */
  89. /*
  90. * Copyright (c) 1995 by P.J. Plauger. ALL RIGHTS RESERVED.
  91. * Consult your license regarding permissions and restrictions.
  92. */
  93. /*
  94. * This file is derived from software bearing the following
  95. * restrictions:
  96. *
  97. * Copyright (c) 1994
  98. * Hewlett-Packard Company
  99. *
  100. * Permission to use, copy, modify, distribute and sell this
  101. * software and its documentation for any purpose is hereby
  102. * granted without fee, provided that the above copyright notice
  103. * appear in all copies and that both that copyright notice and
  104. * this permission notice appear in supporting documentation.
  105. * Hewlett-Packard Company makes no representations about the
  106. * suitability of this software for any purpose. It is provided
  107. * "as is" without express or implied warranty.
  108. */