⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 freelist.h

📁 Conditional Random Fields的训练识别工具
💻 H
字号:
/*  CRF++ -- Yet Another CRF toolkit  $Id: freelist.h 1528 2006-08-07 02:39:50Z taku $;  Copyright(C) 2005 Taku Kudo <taku@chasen.org>  This is free software with ABSOLUTELY NO WARRANTY.  This library is free software; you can redistribute it and/or  modify it under the terms of the GNU Lesser General Public  License as published by the Free Software Foundation; either  version 2.1 of the License, or(at your option) any later version.  This library is distributed in the hope that it will be useful,  but WITHOUT ANY WARRANTY; without even the implied warranty of  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU  Lesser General Public License for more details.  You should have received a copy of the GNU Lesser General Public  License along with this library; if not, write to the Free Software  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA*/#ifndef _CRFPP_FREELIST_H#define _CRFPP_FREELIST_H#include <vector>namespace CRFPP{  template <class T>    class Length { public: size_t operator()(const T *str) const { return 1; } };  class charLength { public: size_t operator()(const char *str) const  { return strlen(str) + 1; } };  template <class T, class LengthFunc = Length<T> >    class FreeList    {      private:      std::vector <T *> freeList;      size_t pi;      size_t li;      size_t size;      public:      void free() { li = pi = 0; }      T* alloc(size_t len = 1)      {        if ((pi + len) >= size) { li++; pi = 0; }        if (li == freeList.size()) {          freeList.push_back(new T [size]);        }        T* r = freeList[li] + pi;        pi += len;        return r;      }      T* dup(T *src, size_t len = 0)      {        if (! len) len = LengthFunc () (src);        T *p = alloc(len);        if (src == 0) memset (p, 0, len * sizeof (T));        else        memcpy(p, src, len * sizeof(T));        return p;      }      void set_size(size_t n) { size = n; }      FreeList(size_t _size): pi(0), li(0), size(_size) {}      FreeList(): pi(0), li(0), size(0) {};      ~FreeList()      {        for (li = 0; li < freeList.size(); ++li) {          delete [] freeList[li];        }      }    };  typedef FreeList<char, charLength> StrFreeList;}#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -