Source code of Windows XP (NT5)
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.

46 lines
1.3 KiB

  1. #ifndef __VITERBI__
  2. #define __VITERBI__
  3. #include <assert.h>
  4. typedef float (_cdecl *ConcatCostFn) (const void *pElem1, const void *pElem2, float fUnitCost);
  5. typedef float (_cdecl *UnitCostFn) (const void *pElem1, const int iPos);
  6. class CPtrArray
  7. {
  8. private:
  9. int m_iSize;
  10. int m_iTop;
  11. int m_iGrow;
  12. void **m_rgpv;
  13. public:
  14. CPtrArray();
  15. ~CPtrArray();
  16. int Add(void *pElem);
  17. void *Get(int iElem) const {if ((iElem >= m_iTop) || (iElem < 0)) return NULL;
  18. return m_rgpv[iElem];}
  19. void *&ElementAt(int iElem) {assert((iElem < m_iTop) && (iElem >= 0));
  20. return m_rgpv[iElem];}
  21. int GetSize() {return m_iSize;}
  22. int GetUsed() {return m_iTop;}
  23. void SetSize(int iSize, int iGrowSize=-1);
  24. void *operator[](int iElem) const {return Get(iElem);}
  25. void *&operator[](int iElem) {return ElementAt(iElem);}
  26. };
  27. class CViterbi
  28. {
  29. public:
  30. CViterbi();
  31. ~CViterbi();
  32. int Init (int iLen, int iInitialDepth, int iGrowSize=-1);
  33. int Add (int iPos, void *pElem);
  34. int FindBestPath (ConcatCostFn pConcatCostFunction, UnitCostFn pUnitCostFunction, float *pfCost);
  35. float m_fPruneLevel;
  36. ConcatCostFn m_pConcatCostFunction;
  37. UnitCostFn m_pUnitCostFunction;
  38. void **m_rgpBestElems;
  39. private:
  40. int m_iLen;
  41. CPtrArray **m_rgpElemArray;
  42. };
  43. #endif