freetype-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[freetype2] master c98a40f 1/2: [bdf, base] Lift hash functions from bdf


From: Werner LEMBERG
Subject: [freetype2] master c98a40f 1/2: [bdf, base] Lift hash functions from bdf driver to base module.
Date: Sat, 19 Dec 2015 16:02:51 +0000

branch: master
commit c98a40f99d468e280e41bcbd277b354b850dc5ee
Author: Werner Lemberg <address@hidden>
Commit: Werner Lemberg <address@hidden>

    [bdf, base] Lift hash functions from bdf driver to base module.
    
    * src/base/fthash.c, include/freetype/internal/fthash.h: New files,
    containing (massaged) code from `bdflib.c' and `bdf.h'.
    
    * include/freetype/internal/internal.h (FT_INTERNAL_HASH_H): New
    macro.
    
    * src/base/ftbase.c: Include `fthash.c'.
    
    * src/base/Jamfile (_sources): Add `fthash'.
    
    * src/base/rules.mk (BASE_SRC): Add `fthash.c'.
    
    * docs/LICENSE.TXT: Updated.
---
 ChangeLog                            |   18 +++
 docs/LICENSE.TXT                     |    6 +-
 include/freetype/internal/fthash.h   |  100 +++++++++++++++++
 include/freetype/internal/internal.h |    1 +
 src/base/Jamfile                     |    1 +
 src/base/ftbase.c                    |    1 +
 src/base/fthash.c                    |  201 ++++++++++++++++++++++++++++++++++
 src/base/rules.mk                    |    1 +
 8 files changed, 327 insertions(+), 2 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 5fb6f4a..8a28eff 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,21 @@
+2015-12-19  Werner Lemberg  <address@hidden>
+
+       [bdf, base] Lift hash functions from bdf driver to base module.
+
+       * src/base/fthash.c, include/freetype/internal/fthash.h: New files,
+       containing (massaged) code from `bdflib.c' and `bdf.h'.
+
+       * include/freetype/internal/internal.h (FT_INTERNAL_HASH_H): New
+       macro.
+
+       * src/base/ftbase.c: Include `fthash.c'.
+
+       * src/base/Jamfile (_sources): Add `fthash'.
+
+       * src/base/rules.mk (BASE_SRC): Add `fthash.c'.
+
+       * docs/LICENSE.TXT: Updated.
+
 2015-12-15  Werner Lemberg  <address@hidden>
 
        [autofit] Add blue-zone support for Bengali script.
diff --git a/docs/LICENSE.TXT b/docs/LICENSE.TXT
index 99dc342..af5a1c5 100644
--- a/docs/LICENSE.TXT
+++ b/docs/LICENSE.TXT
@@ -23,9 +23,11 @@ any of your projects or products.
     GPL.  Note  that the  FTL is  incompatible  with  GPLv2 due  to  its
     advertisement clause.
 
-The contributed BDF and PCF drivers come with a license similar  to that
+The contributed BDF and PCF drivers  come with a license similar to that
 of the X Window System.  It is compatible to the above two licenses (see
-file src/bdf/README and src/pcf/README).
+file src/bdf/README and  src/pcf/README).  The same holds  for the files
+`fthash.c' and  `fthash.h'; their  code was  part of  the BDF  driver in
+earlier FreeType versions.
 
 The gzip module uses the zlib license (see src/gzip/zlib.h) which too is
 compatible to the above two licenses.
diff --git a/include/freetype/internal/fthash.h 
b/include/freetype/internal/fthash.h
new file mode 100644
index 0000000..2d67942
--- /dev/null
+++ b/include/freetype/internal/fthash.h
@@ -0,0 +1,100 @@
+/***************************************************************************/
+/*                                                                         */
+/*  fthash.h                                                               */
+/*                                                                         */
+/*    Hashing functions (specification).                                   */
+/*                                                                         */
+/***************************************************************************/
+
+/*
+ * Copyright 2000 Computing Research Labs, New Mexico State University
+ * Copyright 2001-2015
+ *   Francesco Zappa Nardelli
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE COMPUTING RESEARCH LAB OR NEW MEXICO STATE UNIVERSITY BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
+ * OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+  /*************************************************************************/
+  /*                                                                       */
+  /*  This file is based on code from bdf.c,v 1.22 2000/03/16 20:08:50     */
+  /*                                                                       */
+  /*  taken from Mark Leisher's xmbdfed package                            */
+  /*                                                                       */
+  /*************************************************************************/
+
+
+#ifndef __FTHASH_H__
+#define __FTHASH_H__
+
+
+#include <ft2build.h>
+#include FT_FREETYPE_H
+
+
+FT_BEGIN_HEADER
+
+
+  typedef struct  FT_HashnodeRec_
+  {
+    const char*  key;
+    size_t       data;
+
+  } FT_HashnodeRec;
+
+  typedef struct FT_HashnodeRec_  *FT_Hashnode;
+
+
+  typedef struct  FT_HashRec_
+  {
+    FT_UInt  limit;
+    FT_UInt  size;
+    FT_UInt  used;
+
+    FT_Hashnode*  table;
+
+  } FT_HashRec;
+
+  typedef struct FT_HashRec_  *FT_Hash;
+
+
+  FT_Error
+  ft_hash_init( FT_Hash    hash,
+                FT_Memory  memory );
+
+  void
+  ft_hash_free( FT_Hash    hash,
+                FT_Memory  memory );
+
+  FT_Error
+  ft_hash_insert( char*      key,
+                  size_t     data,
+                  FT_Hash    ht,
+                  FT_Memory  memory );
+
+  FT_Hashnode
+  ft_hash_lookup( const char*  key,
+                  FT_Hash      hash );
+
+FT_END_HEADER
+
+
+#endif /* __FTHASH_H__ */
+
+
+/* END */
diff --git a/include/freetype/internal/internal.h 
b/include/freetype/internal/internal.h
index 809ce59..9f52953 100644
--- a/include/freetype/internal/internal.h
+++ b/include/freetype/internal/internal.h
@@ -30,6 +30,7 @@
 #define FT_INTERNAL_MEMORY_H              <freetype/internal/ftmemory.h>
 #define FT_INTERNAL_DEBUG_H               <freetype/internal/ftdebug.h>
 #define FT_INTERNAL_CALC_H                <freetype/internal/ftcalc.h>
+#define FT_INTERNAL_HASH_H                <freetype/internal/fthash.h>
 #define FT_INTERNAL_DRIVER_H              <freetype/internal/ftdriver.h>
 #define FT_INTERNAL_TRACE_H               <freetype/internal/fttrace.h>
 #define FT_INTERNAL_GLYPH_LOADER_H        <freetype/internal/ftgloadr.h>
diff --git a/src/base/Jamfile b/src/base/Jamfile
index e39fb09..c291cf4 100644
--- a/src/base/Jamfile
+++ b/src/base/Jamfile
@@ -22,6 +22,7 @@ SubDir  FT2_TOP $(FT2_SRC_DIR) base ;
                ftcalc
                ftdbgmem
                ftgloadr
+               fthash
                ftobjs
                ftoutln
                ftpic
diff --git a/src/base/ftbase.c b/src/base/ftbase.c
index 253dfb7..ed57a9e 100644
--- a/src/base/ftbase.c
+++ b/src/base/ftbase.c
@@ -26,6 +26,7 @@
 #include "ftcalc.c"
 #include "ftdbgmem.c"
 #include "ftgloadr.c"
+#include "fthash.c"
 #include "ftobjs.c"
 #include "ftoutln.c"
 #include "ftrfork.c"
diff --git a/src/base/fthash.c b/src/base/fthash.c
new file mode 100644
index 0000000..c26077c
--- /dev/null
+++ b/src/base/fthash.c
@@ -0,0 +1,201 @@
+/***************************************************************************/
+/*                                                                         */
+/*  fthash.c                                                               */
+/*                                                                         */
+/*    Hashing functions (body).                                            */
+/*                                                                         */
+/***************************************************************************/
+
+/*
+ * Copyright 2000 Computing Research Labs, New Mexico State University
+ * Copyright 2001-2015
+ *   Francesco Zappa Nardelli
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE COMPUTING RESEARCH LAB OR NEW MEXICO STATE UNIVERSITY BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
+ * OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+  /*************************************************************************/
+  /*                                                                       */
+  /*  This file is based on code from bdf.c,v 1.22 2000/03/16 20:08:50     */
+  /*                                                                       */
+  /*  taken from Mark Leisher's xmbdfed package                            */
+  /*                                                                       */
+  /*************************************************************************/
+
+
+#include <ft2build.h>
+#include FT_INTERNAL_HASH_H
+
+
+#define INITIAL_HT_SIZE  241
+
+
+  static FT_Hashnode*
+  hash_bucket( const char*  key,
+               FT_Hash      hash )
+  {
+    const char*   kp  = key;
+    FT_ULong      res = 0;
+    FT_Hashnode*  bp  = hash->table;
+    FT_Hashnode*  ndp;
+
+
+    /* Mocklisp hash function. */
+    while ( *kp )
+      res = ( res << 5 ) - res + (FT_ULong)*kp++;
+
+    ndp = bp + ( res % hash->size );
+    while ( *ndp )
+    {
+      kp = (*ndp)->key;
+
+      if ( kp[0] == key[0]           &&
+           ft_strcmp( kp, key ) == 0 )
+        break;
+
+      ndp--;
+      if ( ndp < bp )
+        ndp = bp + ( hash->size - 1 );
+    }
+
+    return ndp;
+  }
+
+
+  static FT_Error
+  hash_rehash( FT_Hash    hash,
+               FT_Memory  memory )
+  {
+    FT_Hashnode*  obp = hash->table;
+    FT_Hashnode*  bp;
+    FT_Hashnode*  nbp;
+
+    FT_UInt   i, sz = hash->size;
+    FT_Error  error = FT_Err_Ok;
+
+
+    hash->size <<= 1;
+    hash->limit  = hash->size / 3;
+
+    if ( FT_NEW_ARRAY( hash->table, hash->size ) )
+      goto Exit;
+
+    for ( i = 0, bp = obp; i < sz; i++, bp++ )
+    {
+      if ( *bp )
+      {
+        nbp = hash_bucket( (*bp)->key, hash );
+        *nbp = *bp;
+      }
+    }
+
+    FT_FREE( obp );
+
+  Exit:
+    return error;
+  }
+
+
+  FT_Error
+  ft_hash_init( FT_Hash    hash,
+                FT_Memory  memory )
+  {
+    FT_UInt   sz = INITIAL_HT_SIZE;
+    FT_Error  error;
+
+
+    hash->size  = sz;
+    hash->limit = sz / 3;
+    hash->used  = 0;
+
+    FT_MEM_NEW_ARRAY( hash->table, sz );
+
+    return error;
+  }
+
+
+  void
+  ft_hash_free( FT_Hash    hash,
+                FT_Memory  memory )
+  {
+    if ( hash )
+    {
+      FT_UInt       sz = hash->size;
+      FT_Hashnode*  bp = hash->table;
+      FT_UInt       i;
+
+
+      for ( i = 0; i < sz; i++, bp++ )
+        FT_FREE( *bp );
+
+      FT_FREE( hash->table );
+    }
+  }
+
+
+  FT_Error
+  ft_hash_insert( char*      key,
+                  size_t     data,
+                  FT_Hash    hash,
+                  FT_Memory  memory )
+  {
+    FT_Hashnode   nn;
+    FT_Hashnode*  bp    = hash_bucket( key, hash );
+    FT_Error      error = FT_Err_Ok;
+
+
+    nn = *bp;
+    if ( !nn )
+    {
+      if ( FT_NEW( nn ) )
+        goto Exit;
+      *bp = nn;
+
+      nn->key  = key;
+      nn->data = data;
+
+      if ( hash->used >= hash->limit )
+      {
+        error = hash_rehash( hash, memory );
+        if ( error )
+          goto Exit;
+      }
+
+      hash->used++;
+    }
+    else
+      nn->data = data;
+
+  Exit:
+    return error;
+  }
+
+
+  FT_Hashnode
+  ft_hash_lookup( const char*  key,
+                  FT_Hash      hash )
+  {
+    FT_Hashnode*  np = hash_bucket( key, hash );
+
+
+    return *np;
+  }
+
+
+/* END */
diff --git a/src/base/rules.mk b/src/base/rules.mk
index 1852e08..b22474f 100644
--- a/src/base/rules.mk
+++ b/src/base/rules.mk
@@ -41,6 +41,7 @@ BASE_SRC := $(BASE_DIR)/basepic.c  \
             $(BASE_DIR)/ftcalc.c   \
             $(BASE_DIR)/ftdbgmem.c \
             $(BASE_DIR)/ftgloadr.c \
+            $(BASE_DIR)/fthash.c   \
             $(BASE_DIR)/ftobjs.c   \
             $(BASE_DIR)/ftoutln.c  \
             $(BASE_DIR)/ftpic.c    \



reply via email to

[Prev in Thread] Current Thread [Next in Thread]