Skip to content

Commit

Permalink
Removed redundant hashfn.cpp and repurposed hashfn.h as stl compatibi…
Browse files Browse the repository at this point in the history
…lity

git-svn-id: https://tesseract-ocr.googlecode.com/svn/trunk@937 d0cd1f9f-072b-0410-8dd7-cf729c803f20
  • Loading branch information
theraysmith@gmail.com committed Jan 9, 2014
1 parent 9c25eda commit 0ea4987
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 68 deletions.
2 changes: 1 addition & 1 deletion ccutil/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ libtesseract_ccutil_la_SOURCES = \
ambigs.cpp basedir.cpp bits16.cpp bitvector.cpp \
ccutil.cpp clst.cpp \
elst2.cpp elst.cpp errcode.cpp \
globaloc.cpp hashfn.cpp indexmapbidi.cpp \
globaloc.cpp indexmapbidi.cpp \
mainblk.cpp memry.cpp \
serialis.cpp strngs.cpp \
tessdatamanager.cpp tprintf.cpp \
Expand Down
56 changes: 0 additions & 56 deletions ccutil/hashfn.cpp

This file was deleted.

79 changes: 68 additions & 11 deletions ccutil/hashfn.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/**********************************************************************
* File: hashfn.h (Formerly hash.h)
* Description: Simple hash function.
* Author: Ray Smith
* Created: Thu Jan 16 11:47:59 GMT 1992
* Description: Portability hacks for hash_map, hash_set and unique_ptr.
* Author: Ray Smith
* Created: Wed Jan 08 14:08:25 PST 2014
*
* (C) Copyright 1992, Hewlett-Packard Ltd.
* (C) Copyright 2014, Google Inc.
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at
Expand All @@ -20,11 +20,68 @@
#ifndef HASHFN_H
#define HASHFN_H

#include "host.h"

inT32 hash( //hash function
inT32 bits, //bits in hash function
void *key, //key to hash
inT32 keysize //size of key
);
#ifdef USE_STD_NAMESPACE
#if (__cplusplus >= 201103L) || defined(_MSC_VER) // Visual Studio
#include <unordered_map>
#include <unordered_set>
#ifdef _MSC_VER
#if (_MSC_VER >= 1500 && _MSC_VER < 1600) // Visual Studio 2008
using namespace std::tr1;
#else
using std::unordered_map;
using std::unordered_set;
#endif
#else // _MSC_VER
#include <memory>
#define std::unique_ptr SmartPtr
#define HAVE_UNIQUE_PTR
#endif // _MSC_VER
#elif (defined(__GNUC__) && (((__GNUC__ == 3) && ( __GNUC_MINOR__ > 0)) || \
__GNUC__ >= 4)) // gcc
// hash_set is deprecated in gcc
#include <ext/hash_map>
#include <ext/hash_set>
using __gnu_cxx::hash_map;
using __gnu_cxx::hash_set;
#define unordered_map hash_map
#define unordered_set hash_set
#else
#include <hash_map>
#include <hash_set>
#endif // gcc
#else // USE_STD_NAMESPACE
#include <hash_map>
#include <hash_set>
#define unordered_map hash_map
#define unordered_set hash_set
#endif // USE_STD_NAMESPACE

#ifndef HAVE_UNIQUE_PTR
// Trivial smart ptr. Expand to add features of std::unique_ptr as required.
template<class T> class SmartPtr {
public:
SmartPtr() : ptr_(NULL) {}
SmartPtr(T* ptr) : ptr_(ptr) {}
~SmartPtr() {
delete ptr_;
}

T* get() const {
return ptr_;
}
void reset(T* ptr) {
if (ptr_ != NULL) delete ptr_;
ptr_ = ptr;
}
bool operator==(const T* ptr) const {
return ptr_ == ptr;
}
T* operator->() const {
return ptr_;
}
private:
T* ptr_;
};
#endif // HAVE_UNIQUE_PTR

#endif // HASHFN_H

0 comments on commit 0ea4987

Please sign in to comment.