CLucene源码剖析(2)

文件:VoidList.h

注释说明:中文注释

代码:

/*------------------------------------------------------------------------------
* Copyright (C) 2003-2006 Ben van Klinken and the CLucene Team
*
* Distributable under the terms of either the Apache License (Version 2.0) or
* the GNU Lesser General Public License, as specified in the COPYING file.
------------------------------------------------------------------------------*/
#ifndef _lucene_util_VoidList_
#define _lucene_util_VoidList_

#if defined(_LUCENE_PRAGMA_ONCE)
# pragma once
#endif

#include "Equators.h"

CL_NS_DEF(util)

 //_base实际上是_kt的容器
 //_valueDeletor是对容器中元素回收的处理方式
 template<typename _kt,typename _base,typename _valueDeletor>
 class __CLList:public _base,LUCENE_BASE {
 private:
  //如果为true,则要调用_valueDeletor::doDelete进行资源回收
  bool dv;
  typedef _base base;
 public:
        DEFINE_MUTEX(THIS_LOCK)

  typedef typename _base::const_iterator const_iterator;
  typedef typename _base::iterator iterator;

  virtual ~__CLList(){
   clear();
  }

  __CLList ( const bool deleteValue ):
   dv(deleteValue)
  {
  }
  //是否需要回收
  void setDoDelete(bool val){ dv=val; }

  //sets array to the contents of this array.
  //array must be size+1, otherwise memory may be overwritten
  //把内容转换成数组
  void toArray(_kt* into) const{
   int i=0;
   for ( const_iterator itr=base::begin();itr!=base::end();itr++ ){
    into[i] = *itr;
    i++;
   }
   into[i] = NULL;
  }

  //设定容器的第i个元素
  void set(int32_t i, _kt val) {
   if ( dv )
    _valueDeletor::doDelete((*this)[i]);
   (*this)[i] = val;
  }

  //todo: check this
  //删除最后一个元素
  void delete_back(){
   if ( base::size() > 0 ){
    iterator itr = base::end();
    if ( itr != base::begin())
     itr --;
    _kt key = *itr;
    base::erase(itr);
    if ( dv )
     _valueDeletor::doDelete(key);
   }
  }
  //删除第一个元素
  void delete_front(){
   if ( base::size() > 0 ){
    iterator itr = base::begin();
    _kt key = *itr;
    base::erase(itr);
    if ( dv )
     _valueDeletor::doDelete(key);
   }
  }

  //回收所有元素
  void clear(){
   if ( dv ){
    iterator itr = base::begin();
    while ( itr != base::end() ){
     _valueDeletor::doDelete(*itr);
     itr++;
    }
   }
   //容器clear
   base::clear();
  }

  //从容器中删除某个特定位置的元素,  
  void remove(int32_t i, bool dontDelete=false){
   iterator itr=base::begin();
   //迭代器+操作表明是顺序容器
   itr+=i;
   _kt key = *itr;
   base::erase( itr );
   if ( dv && !dontDelete )
    _valueDeletor::doDelete(key);
  }
  //同上,不过此处指定删除迭代器所指元素
  void remove(iterator itr, bool dontDelete=false){
   _kt key = *itr;
   base::erase( itr );
   if ( dv && !dontDelete )
    _valueDeletor::doDelete(key);
  }

 };

//growable arrays of Objects (like a collection or list)
//a list, so can contain duplicates
//it grows in chunks... todo: check jlucene for initial size of array, and growfactors
//表明__CLList中的容器是vector
template<typename _kt, typename _valueDeletor=CL_NS(util)::Deletor::Dummy>
class CLVector:public __CLList<_kt, CL_NS_STD(vector)<_kt> , _valueDeletor>
{
public:
 CLVector ( const bool deleteValue=true ):
   //构造函数
   __CLList<_kt, CL_NS_STD(vector)<_kt> , _valueDeletor>(deleteValue)
 {
 }
};

//An array-backed implementation of the List interface
//a list, so can contain duplicates
//*** a very simple list - use <valarray>
//(This class is roughly equivalent to Vector, except that it is unsynchronized.)
#define CLArrayList CLVector
#define CLHashSet CLHashList

//implementation of the List interface, provides access to the first and last list elements in O(1)
//no comparator is required... and so can contain duplicates
//a simple list with no comparator
//*** a very simple list - use <list>
#ifdef LUCENE_DISABLE_HASHING
   #define CLHashList CLSetList
#else

//表明__CLList中的容器是hash_set(非标准库)
template<typename _kt,
 typename _Comparator=CL_NS(util)::Compare::TChar,
 typename _valueDeletor=CL_NS(util)::Deletor::Dummy>
class CLHashList:public __CLList<_kt, CL_NS_HASHING(hash_set)<_kt,_Comparator> , _valueDeletor>
{
public:
 CLHashList ( const bool deleteValue=true ):
   __CLList<_kt, CL_NS_HASHING(hash_set)<_kt,_Comparator> , _valueDeletor>(deleteValue)
 {
 }
};
#endif

//表明__CLList中的容器是list
template<typename _kt, typename _valueDeletor=CL_NS(util)::Deletor::Dummy>
class CLLinkedList:public __CLList<_kt, CL_NS_STD(list)<_kt> , _valueDeletor>
{
public:
 CLLinkedList ( const bool deleteValue=true ):
   __CLList<_kt, CL_NS_STD(list)<_kt> , _valueDeletor>(deleteValue)
 {
 }
};

//表明__CLList中的容器是set
template<typename _kt,
 typename _Comparator=CL_NS(util)::Compare::TChar,
 typename _valueDeletor=CL_NS(util)::Deletor::Dummy>
class CLSetList:public __CLList<_kt, CL_NS_STD(set)<_kt,_Comparator> , _valueDeletor>
{
public:
 CLSetList ( const bool deleteValue=true ):
   __CLList<_kt, CL_NS_STD(set)<_kt,_Comparator> , _valueDeletor>(deleteValue)
 {
 }
};

CL_NS_END
#endif
 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
大名鼎鼎的clucene,是lucene的c++ 版; CLucene README ============== ------------------------------------------------------ CLucene is a C++ port of Lucene. It is a high-performance, full-featured text search engine written in C++. CLucene is faster than lucene as it is written in C++. ------------------------------------------------------ CLucene has contributions from many, see AUTHORS CLucene is distributed under the GNU Lesser General Public License (LGPL) *or* the Apache License, Version 2.0 See the LGPL.license and APACHE.license for the respective license information. Read COPYING for more about the license. Installation ------------ * For Linux, MacOSX, cygwin and MinGW build information, read INSTALL. * Boost.Jam files are provided in the root directory and subdirectories. * Microsoft Visual Studio (6&7) are provided in the win32 folder. Mailing List ------------ Questions and discussion should be directed to the CLucene mailing list at clucene-developers@lists.sourceforge.net Find subscription instructions at http://lists.sourceforge.net/lists/listinfo/clucene-developers Suggestions and bug reports can be made on our bug tracking database (http://sourceforge.net/tracker/?group_id=80013&atid=558446) The latest version ------------------ Details of the latest version can be found on the CLucene sourceforge project web site: http://www.sourceforge.net/projects/clucene Documentation ------------- Documentation is provided at http://clucene.sourceforge.net/doc/doxygen/html/ You can also build your own documentation by running doxygen from the root directory of clucene. CLucene is a very close port of Java Lucene, so you can also try looking at the Java Docs on http://lucene.apache.org/java/ Performance ----------- Very little benchmarking has been done on clucene. Andi Vajda posted some limited statistics on the clucene list a while ago with the following results. There are 250 HTML files under $JAVA_HOME/docs/api/java/util for about 6108kb of HTML

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值