extlzham 0.0.1.PROTOTYPE
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
 - data/LICENSE.md +27 -0
 - data/README.md +21 -0
 - data/Rakefile +143 -0
 - data/contrib/lzham/LICENSE +22 -0
 - data/contrib/lzham/README.md +209 -0
 - data/contrib/lzham/include/lzham.h +781 -0
 - data/contrib/lzham/lzhamcomp/lzham_comp.h +38 -0
 - data/contrib/lzham/lzhamcomp/lzham_lzbase.cpp +244 -0
 - data/contrib/lzham/lzhamcomp/lzham_lzbase.h +45 -0
 - data/contrib/lzham/lzhamcomp/lzham_lzcomp.cpp +608 -0
 - data/contrib/lzham/lzhamcomp/lzham_lzcomp_internal.cpp +1966 -0
 - data/contrib/lzham/lzhamcomp/lzham_lzcomp_internal.h +472 -0
 - data/contrib/lzham/lzhamcomp/lzham_lzcomp_state.cpp +1413 -0
 - data/contrib/lzham/lzhamcomp/lzham_match_accel.cpp +562 -0
 - data/contrib/lzham/lzhamcomp/lzham_match_accel.h +146 -0
 - data/contrib/lzham/lzhamcomp/lzham_null_threading.h +97 -0
 - data/contrib/lzham/lzhamcomp/lzham_pthreads_threading.cpp +229 -0
 - data/contrib/lzham/lzhamcomp/lzham_pthreads_threading.h +520 -0
 - data/contrib/lzham/lzhamcomp/lzham_threading.h +12 -0
 - data/contrib/lzham/lzhamcomp/lzham_win32_threading.cpp +220 -0
 - data/contrib/lzham/lzhamcomp/lzham_win32_threading.h +368 -0
 - data/contrib/lzham/lzhamdecomp/lzham_assert.cpp +66 -0
 - data/contrib/lzham/lzhamdecomp/lzham_assert.h +40 -0
 - data/contrib/lzham/lzhamdecomp/lzham_checksum.cpp +73 -0
 - data/contrib/lzham/lzhamdecomp/lzham_checksum.h +13 -0
 - data/contrib/lzham/lzhamdecomp/lzham_config.h +23 -0
 - data/contrib/lzham/lzhamdecomp/lzham_core.h +264 -0
 - data/contrib/lzham/lzhamdecomp/lzham_decomp.h +37 -0
 - data/contrib/lzham/lzhamdecomp/lzham_helpers.h +54 -0
 - data/contrib/lzham/lzhamdecomp/lzham_huffman_codes.cpp +262 -0
 - data/contrib/lzham/lzhamdecomp/lzham_huffman_codes.h +14 -0
 - data/contrib/lzham/lzhamdecomp/lzham_lzdecomp.cpp +1527 -0
 - data/contrib/lzham/lzhamdecomp/lzham_lzdecompbase.cpp +131 -0
 - data/contrib/lzham/lzhamdecomp/lzham_lzdecompbase.h +89 -0
 - data/contrib/lzham/lzhamdecomp/lzham_math.h +142 -0
 - data/contrib/lzham/lzhamdecomp/lzham_mem.cpp +284 -0
 - data/contrib/lzham/lzhamdecomp/lzham_mem.h +112 -0
 - data/contrib/lzham/lzhamdecomp/lzham_platform.cpp +157 -0
 - data/contrib/lzham/lzhamdecomp/lzham_platform.h +284 -0
 - data/contrib/lzham/lzhamdecomp/lzham_prefix_coding.cpp +351 -0
 - data/contrib/lzham/lzhamdecomp/lzham_prefix_coding.h +146 -0
 - data/contrib/lzham/lzhamdecomp/lzham_symbol_codec.cpp +1484 -0
 - data/contrib/lzham/lzhamdecomp/lzham_symbol_codec.h +556 -0
 - data/contrib/lzham/lzhamdecomp/lzham_timer.cpp +147 -0
 - data/contrib/lzham/lzhamdecomp/lzham_timer.h +99 -0
 - data/contrib/lzham/lzhamdecomp/lzham_traits.h +141 -0
 - data/contrib/lzham/lzhamdecomp/lzham_types.h +97 -0
 - data/contrib/lzham/lzhamdecomp/lzham_utils.h +58 -0
 - data/contrib/lzham/lzhamdecomp/lzham_vector.cpp +75 -0
 - data/contrib/lzham/lzhamdecomp/lzham_vector.h +588 -0
 - data/contrib/lzham/lzhamlib/lzham_lib.cpp +179 -0
 - data/examples/basic.rb +48 -0
 - data/ext/extconf.rb +26 -0
 - data/ext/extlzham.c +741 -0
 - data/gemstub.rb +22 -0
 - data/lib/extlzham/version.rb +5 -0
 - data/lib/extlzham.rb +153 -0
 - metadata +135 -0
 
| 
         @@ -0,0 +1,99 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            // File: lzham_timer.h
         
     | 
| 
      
 2 
     | 
    
         
            +
            // See Copyright Notice and license at the end of include/lzham.h
         
     | 
| 
      
 3 
     | 
    
         
            +
            #pragma once
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
            namespace lzham
         
     | 
| 
      
 6 
     | 
    
         
            +
            {
         
     | 
| 
      
 7 
     | 
    
         
            +
               typedef unsigned long long timer_ticks;
         
     | 
| 
      
 8 
     | 
    
         
            +
                  
         
     | 
| 
      
 9 
     | 
    
         
            +
               class lzham_timer
         
     | 
| 
      
 10 
     | 
    
         
            +
               {
         
     | 
| 
      
 11 
     | 
    
         
            +
               public:
         
     | 
| 
      
 12 
     | 
    
         
            +
                  lzham_timer();
         
     | 
| 
      
 13 
     | 
    
         
            +
                  lzham_timer(timer_ticks start_ticks);
         
     | 
| 
      
 14 
     | 
    
         
            +
                  
         
     | 
| 
      
 15 
     | 
    
         
            +
                  void start();
         
     | 
| 
      
 16 
     | 
    
         
            +
                  void start(timer_ticks start_ticks);
         
     | 
| 
      
 17 
     | 
    
         
            +
                  
         
     | 
| 
      
 18 
     | 
    
         
            +
                  void stop();
         
     | 
| 
      
 19 
     | 
    
         
            +
                     
         
     | 
| 
      
 20 
     | 
    
         
            +
                  double get_elapsed_secs() const;
         
     | 
| 
      
 21 
     | 
    
         
            +
                  inline double get_elapsed_ms() const { return get_elapsed_secs() * 1000.0f; }
         
     | 
| 
      
 22 
     | 
    
         
            +
                  timer_ticks get_elapsed_us() const;
         
     | 
| 
      
 23 
     | 
    
         
            +
                  
         
     | 
| 
      
 24 
     | 
    
         
            +
                  static void init();
         
     | 
| 
      
 25 
     | 
    
         
            +
                  static inline timer_ticks get_ticks_per_sec() { return g_freq; }
         
     | 
| 
      
 26 
     | 
    
         
            +
                  static timer_ticks get_init_ticks();
         
     | 
| 
      
 27 
     | 
    
         
            +
                  static timer_ticks get_ticks();
         
     | 
| 
      
 28 
     | 
    
         
            +
                  static double ticks_to_secs(timer_ticks ticks);
         
     | 
| 
      
 29 
     | 
    
         
            +
                  static inline double ticks_to_ms(timer_ticks ticks) { return ticks_to_secs(ticks) * 1000.0f; }
         
     | 
| 
      
 30 
     | 
    
         
            +
                  static inline double get_secs() { return ticks_to_secs(get_ticks()); }
         
     | 
| 
      
 31 
     | 
    
         
            +
                  static inline double get_ms() { return ticks_to_ms(get_ticks()); }
         
     | 
| 
      
 32 
     | 
    
         
            +
                               
         
     | 
| 
      
 33 
     | 
    
         
            +
               private:
         
     | 
| 
      
 34 
     | 
    
         
            +
                  static timer_ticks g_init_ticks;
         
     | 
| 
      
 35 
     | 
    
         
            +
                  static timer_ticks g_freq;
         
     | 
| 
      
 36 
     | 
    
         
            +
                  static double g_inv_freq;
         
     | 
| 
      
 37 
     | 
    
         
            +
                  
         
     | 
| 
      
 38 
     | 
    
         
            +
                  timer_ticks m_start_time;
         
     | 
| 
      
 39 
     | 
    
         
            +
                  timer_ticks m_stop_time;
         
     | 
| 
      
 40 
     | 
    
         
            +
                  
         
     | 
| 
      
 41 
     | 
    
         
            +
                  bool m_started : 1;
         
     | 
| 
      
 42 
     | 
    
         
            +
                  bool m_stopped : 1;
         
     | 
| 
      
 43 
     | 
    
         
            +
               };
         
     | 
| 
      
 44 
     | 
    
         
            +
             
     | 
| 
      
 45 
     | 
    
         
            +
               enum var_args_t { cVarArgs };
         
     | 
| 
      
 46 
     | 
    
         
            +
               
         
     | 
| 
      
 47 
     | 
    
         
            +
            #if LZHAM_PERF_SECTIONS
         
     | 
| 
      
 48 
     | 
    
         
            +
               class scoped_perf_section
         
     | 
| 
      
 49 
     | 
    
         
            +
               {
         
     | 
| 
      
 50 
     | 
    
         
            +
               public:
         
     | 
| 
      
 51 
     | 
    
         
            +
                  inline scoped_perf_section() :
         
     | 
| 
      
 52 
     | 
    
         
            +
                     m_start_ticks(lzham_timer::get_ticks())
         
     | 
| 
      
 53 
     | 
    
         
            +
                  {
         
     | 
| 
      
 54 
     | 
    
         
            +
                     m_name[0] = '?';
         
     | 
| 
      
 55 
     | 
    
         
            +
                     m_name[1] = '\0';
         
     | 
| 
      
 56 
     | 
    
         
            +
                  }
         
     | 
| 
      
 57 
     | 
    
         
            +
                  
         
     | 
| 
      
 58 
     | 
    
         
            +
                  inline scoped_perf_section(const char *pName) :
         
     | 
| 
      
 59 
     | 
    
         
            +
                     m_start_ticks(lzham_timer::get_ticks())
         
     | 
| 
      
 60 
     | 
    
         
            +
                  {
         
     | 
| 
      
 61 
     | 
    
         
            +
                     strcpy_s(m_name, pName);
         
     | 
| 
      
 62 
     | 
    
         
            +
                     
         
     | 
| 
      
 63 
     | 
    
         
            +
                     lzham_buffered_printf("Thread: 0x%08X, BEGIN Time: %3.3fms, Section: %s\n", GetCurrentThreadId(), lzham_timer::ticks_to_ms(m_start_ticks), m_name);
         
     | 
| 
      
 64 
     | 
    
         
            +
                  }
         
     | 
| 
      
 65 
     | 
    
         
            +
                  
         
     | 
| 
      
 66 
     | 
    
         
            +
                  inline scoped_perf_section(var_args_t, const char *pName, ...) :
         
     | 
| 
      
 67 
     | 
    
         
            +
                     m_start_ticks(lzham_timer::get_ticks())
         
     | 
| 
      
 68 
     | 
    
         
            +
                  {
         
     | 
| 
      
 69 
     | 
    
         
            +
                     va_list args;
         
     | 
| 
      
 70 
     | 
    
         
            +
                     va_start(args, pName);
         
     | 
| 
      
 71 
     | 
    
         
            +
                     vsprintf_s(m_name, sizeof(m_name), pName, args);
         
     | 
| 
      
 72 
     | 
    
         
            +
                     va_end(args);
         
     | 
| 
      
 73 
     | 
    
         
            +
                     
         
     | 
| 
      
 74 
     | 
    
         
            +
                     lzham_buffered_printf("Thread: 0x%08X, BEGIN Time: %3.3fms, Section: %s\n", GetCurrentThreadId(), lzham_timer::ticks_to_ms(m_start_ticks), m_name);
         
     | 
| 
      
 75 
     | 
    
         
            +
                  }
         
     | 
| 
      
 76 
     | 
    
         
            +
               
         
     | 
| 
      
 77 
     | 
    
         
            +
                  inline ~scoped_perf_section()
         
     | 
| 
      
 78 
     | 
    
         
            +
                  {
         
     | 
| 
      
 79 
     | 
    
         
            +
                     double end_ms = lzham_timer::get_ms();
         
     | 
| 
      
 80 
     | 
    
         
            +
                     double start_ms = lzham_timer::ticks_to_ms(m_start_ticks);
         
     | 
| 
      
 81 
     | 
    
         
            +
                     
         
     | 
| 
      
 82 
     | 
    
         
            +
                     lzham_buffered_printf("Thread: 0x%08X, END Time: %3.3fms, Total: %3.3fms, Section: %s\n", GetCurrentThreadId(), end_ms, end_ms - start_ms, m_name);
         
     | 
| 
      
 83 
     | 
    
         
            +
                  }
         
     | 
| 
      
 84 
     | 
    
         
            +
             
     | 
| 
      
 85 
     | 
    
         
            +
               private:
         
     | 
| 
      
 86 
     | 
    
         
            +
                  char m_name[64];   
         
     | 
| 
      
 87 
     | 
    
         
            +
                  timer_ticks m_start_ticks;
         
     | 
| 
      
 88 
     | 
    
         
            +
               };
         
     | 
| 
      
 89 
     | 
    
         
            +
            #else
         
     | 
| 
      
 90 
     | 
    
         
            +
               class scoped_perf_section
         
     | 
| 
      
 91 
     | 
    
         
            +
               {
         
     | 
| 
      
 92 
     | 
    
         
            +
               public:
         
     | 
| 
      
 93 
     | 
    
         
            +
                  inline scoped_perf_section() { }
         
     | 
| 
      
 94 
     | 
    
         
            +
                  inline scoped_perf_section(const char *pName) { (void)pName; }
         
     | 
| 
      
 95 
     | 
    
         
            +
                  inline scoped_perf_section(var_args_t, const char *pName, ...) { (void)pName; }
         
     | 
| 
      
 96 
     | 
    
         
            +
               };
         
     | 
| 
      
 97 
     | 
    
         
            +
            #endif // LZHAM_PERF_SECTIONS   
         
     | 
| 
      
 98 
     | 
    
         
            +
             
     | 
| 
      
 99 
     | 
    
         
            +
            } // namespace lzham
         
     | 
| 
         @@ -0,0 +1,141 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            // File: lzham_traits.h
         
     | 
| 
      
 2 
     | 
    
         
            +
            // See Copyright Notice and license at the end of include/lzham.h
         
     | 
| 
      
 3 
     | 
    
         
            +
            #pragma once
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
            namespace lzham
         
     | 
| 
      
 6 
     | 
    
         
            +
            {
         
     | 
| 
      
 7 
     | 
    
         
            +
               template<typename T>
         
     | 
| 
      
 8 
     | 
    
         
            +
               struct scalar_type
         
     | 
| 
      
 9 
     | 
    
         
            +
               {
         
     | 
| 
      
 10 
     | 
    
         
            +
                  enum { cFlag = false };
         
     | 
| 
      
 11 
     | 
    
         
            +
                  static inline void construct(T* p) { helpers::construct(p); }
         
     | 
| 
      
 12 
     | 
    
         
            +
                  static inline void construct(T* p, const T& init) { helpers::construct(p, init); }
         
     | 
| 
      
 13 
     | 
    
         
            +
                  static inline void construct_array(T* p, uint n) { helpers::construct_array(p, n); }
         
     | 
| 
      
 14 
     | 
    
         
            +
                  static inline void destruct(T* p) { helpers::destruct(p); }
         
     | 
| 
      
 15 
     | 
    
         
            +
                  static inline void destruct_array(T* p, uint n) { helpers::destruct_array(p, n); }
         
     | 
| 
      
 16 
     | 
    
         
            +
               };
         
     | 
| 
      
 17 
     | 
    
         
            +
             
     | 
| 
      
 18 
     | 
    
         
            +
               template<typename T> struct scalar_type<T*>
         
     | 
| 
      
 19 
     | 
    
         
            +
               {
         
     | 
| 
      
 20 
     | 
    
         
            +
                  enum { cFlag = true };
         
     | 
| 
      
 21 
     | 
    
         
            +
                  static inline void construct(T** p) { memset(p, 0, sizeof(T*)); }
         
     | 
| 
      
 22 
     | 
    
         
            +
                  static inline void construct(T** p, T* init) { *p = init; }
         
     | 
| 
      
 23 
     | 
    
         
            +
                  static inline void construct_array(T** p, uint n) { memset(p, 0, sizeof(T*) * n); }
         
     | 
| 
      
 24 
     | 
    
         
            +
                  static inline void destruct(T** p) { LZHAM_NOTE_UNUSED(p); }
         
     | 
| 
      
 25 
     | 
    
         
            +
                  static inline void destruct_array(T** p, uint n) { LZHAM_NOTE_UNUSED(p); LZHAM_NOTE_UNUSED(n); }
         
     | 
| 
      
 26 
     | 
    
         
            +
               };
         
     | 
| 
      
 27 
     | 
    
         
            +
             
     | 
| 
      
 28 
     | 
    
         
            +
            #define LZHAM_DEFINE_BUILT_IN_TYPE(X) \
         
     | 
| 
      
 29 
     | 
    
         
            +
               template<> struct scalar_type<X> { \
         
     | 
| 
      
 30 
     | 
    
         
            +
               enum { cFlag = true }; \
         
     | 
| 
      
 31 
     | 
    
         
            +
               static inline void construct(X* p) { memset(p, 0, sizeof(X)); } \
         
     | 
| 
      
 32 
     | 
    
         
            +
               static inline void construct(X* p, const X& init) { memcpy(p, &init, sizeof(X)); } \
         
     | 
| 
      
 33 
     | 
    
         
            +
               static inline void construct_array(X* p, uint n) { memset(p, 0, sizeof(X) * n); } \
         
     | 
| 
      
 34 
     | 
    
         
            +
               static inline void destruct(X* p) { LZHAM_NOTE_UNUSED(p); } \
         
     | 
| 
      
 35 
     | 
    
         
            +
               static inline void destruct_array(X* p, uint n) { LZHAM_NOTE_UNUSED(p); LZHAM_NOTE_UNUSED(n); } };
         
     | 
| 
      
 36 
     | 
    
         
            +
             
     | 
| 
      
 37 
     | 
    
         
            +
               LZHAM_DEFINE_BUILT_IN_TYPE(bool)
         
     | 
| 
      
 38 
     | 
    
         
            +
               LZHAM_DEFINE_BUILT_IN_TYPE(char)
         
     | 
| 
      
 39 
     | 
    
         
            +
               LZHAM_DEFINE_BUILT_IN_TYPE(unsigned char)
         
     | 
| 
      
 40 
     | 
    
         
            +
               LZHAM_DEFINE_BUILT_IN_TYPE(short)
         
     | 
| 
      
 41 
     | 
    
         
            +
               LZHAM_DEFINE_BUILT_IN_TYPE(unsigned short)
         
     | 
| 
      
 42 
     | 
    
         
            +
               LZHAM_DEFINE_BUILT_IN_TYPE(int)
         
     | 
| 
      
 43 
     | 
    
         
            +
               LZHAM_DEFINE_BUILT_IN_TYPE(unsigned int)
         
     | 
| 
      
 44 
     | 
    
         
            +
               LZHAM_DEFINE_BUILT_IN_TYPE(long)
         
     | 
| 
      
 45 
     | 
    
         
            +
               LZHAM_DEFINE_BUILT_IN_TYPE(unsigned long)
         
     | 
| 
      
 46 
     | 
    
         
            +
               LZHAM_DEFINE_BUILT_IN_TYPE(float)
         
     | 
| 
      
 47 
     | 
    
         
            +
               LZHAM_DEFINE_BUILT_IN_TYPE(double)
         
     | 
| 
      
 48 
     | 
    
         
            +
               LZHAM_DEFINE_BUILT_IN_TYPE(long double)
         
     | 
| 
      
 49 
     | 
    
         
            +
               #if defined(WIN32)
         
     | 
| 
      
 50 
     | 
    
         
            +
                  LZHAM_DEFINE_BUILT_IN_TYPE(__int64)
         
     | 
| 
      
 51 
     | 
    
         
            +
                  LZHAM_DEFINE_BUILT_IN_TYPE(unsigned __int64)
         
     | 
| 
      
 52 
     | 
    
         
            +
               #endif
         
     | 
| 
      
 53 
     | 
    
         
            +
             
     | 
| 
      
 54 
     | 
    
         
            +
            #undef LZHAM_DEFINE_BUILT_IN_TYPE
         
     | 
| 
      
 55 
     | 
    
         
            +
             
     | 
| 
      
 56 
     | 
    
         
            +
            // See: http://erdani.org/publications/cuj-2004-06.pdf
         
     | 
| 
      
 57 
     | 
    
         
            +
             
     | 
| 
      
 58 
     | 
    
         
            +
               template<typename T>
         
     | 
| 
      
 59 
     | 
    
         
            +
               struct bitwise_movable { enum { cFlag = false }; };
         
     | 
| 
      
 60 
     | 
    
         
            +
             
     | 
| 
      
 61 
     | 
    
         
            +
            // Defines type Q as bitwise movable.
         
     | 
| 
      
 62 
     | 
    
         
            +
            #define LZHAM_DEFINE_BITWISE_MOVABLE(Q) template<> struct bitwise_movable<Q> { enum { cFlag = true }; };
         
     | 
| 
      
 63 
     | 
    
         
            +
             
     | 
| 
      
 64 
     | 
    
         
            +
               template<typename T>
         
     | 
| 
      
 65 
     | 
    
         
            +
               struct bitwise_copyable { enum { cFlag = false }; };
         
     | 
| 
      
 66 
     | 
    
         
            +
             
     | 
| 
      
 67 
     | 
    
         
            +
               // Defines type Q as bitwise copyable.
         
     | 
| 
      
 68 
     | 
    
         
            +
            #define LZHAM_DEFINE_BITWISE_COPYABLE(Q) template<> struct bitwise_copyable<Q> { enum { cFlag = true }; };
         
     | 
| 
      
 69 
     | 
    
         
            +
             
     | 
| 
      
 70 
     | 
    
         
            +
            #if defined(__APPLE__) || defined(__NetBSD__)
         
     | 
| 
      
 71 
     | 
    
         
            +
               #define LZHAM_IS_POD(T) std::__is_pod<T>::__value
         
     | 
| 
      
 72 
     | 
    
         
            +
            #else
         
     | 
| 
      
 73 
     | 
    
         
            +
               #define LZHAM_IS_POD(T) __is_pod(T)
         
     | 
| 
      
 74 
     | 
    
         
            +
            #endif
         
     | 
| 
      
 75 
     | 
    
         
            +
             
     | 
| 
      
 76 
     | 
    
         
            +
            #define LZHAM_IS_SCALAR_TYPE(T) (scalar_type<T>::cFlag)
         
     | 
| 
      
 77 
     | 
    
         
            +
             
     | 
| 
      
 78 
     | 
    
         
            +
            #define LZHAM_IS_BITWISE_COPYABLE(T) ((scalar_type<T>::cFlag) || (bitwise_copyable<T>::cFlag) || LZHAM_IS_POD(T))
         
     | 
| 
      
 79 
     | 
    
         
            +
             
     | 
| 
      
 80 
     | 
    
         
            +
            #define LZHAM_IS_BITWISE_MOVABLE(T) (LZHAM_IS_BITWISE_COPYABLE(T) || (bitwise_movable<T>::cFlag))
         
     | 
| 
      
 81 
     | 
    
         
            +
             
     | 
| 
      
 82 
     | 
    
         
            +
            #define LZHAM_HAS_DESTRUCTOR(T) ((!scalar_type<T>::cFlag) && (!LZHAM_IS_POD(T)))
         
     | 
| 
      
 83 
     | 
    
         
            +
             
     | 
| 
      
 84 
     | 
    
         
            +
               // From yasli_traits.h:
         
     | 
| 
      
 85 
     | 
    
         
            +
               // Credit goes to Boost;
         
     | 
| 
      
 86 
     | 
    
         
            +
               // also found in the C++ Templates book by Vandevoorde and Josuttis
         
     | 
| 
      
 87 
     | 
    
         
            +
             
     | 
| 
      
 88 
     | 
    
         
            +
               typedef char (&yes_t)[1];
         
     | 
| 
      
 89 
     | 
    
         
            +
               typedef char (&no_t)[2];
         
     | 
| 
      
 90 
     | 
    
         
            +
             
     | 
| 
      
 91 
     | 
    
         
            +
               template <class U> yes_t class_test(int U::*);
         
     | 
| 
      
 92 
     | 
    
         
            +
               template <class U> no_t class_test(...);
         
     | 
| 
      
 93 
     | 
    
         
            +
             
     | 
| 
      
 94 
     | 
    
         
            +
               template <class T> struct is_class
         
     | 
| 
      
 95 
     | 
    
         
            +
               {
         
     | 
| 
      
 96 
     | 
    
         
            +
                  enum { value = (sizeof(class_test<T>(0)) == sizeof(yes_t)) };
         
     | 
| 
      
 97 
     | 
    
         
            +
               };
         
     | 
| 
      
 98 
     | 
    
         
            +
             
     | 
| 
      
 99 
     | 
    
         
            +
               template <typename T> struct is_pointer
         
     | 
| 
      
 100 
     | 
    
         
            +
               {
         
     | 
| 
      
 101 
     | 
    
         
            +
                  enum { value = false };
         
     | 
| 
      
 102 
     | 
    
         
            +
               };
         
     | 
| 
      
 103 
     | 
    
         
            +
             
     | 
| 
      
 104 
     | 
    
         
            +
               template <typename T> struct is_pointer<T*>
         
     | 
| 
      
 105 
     | 
    
         
            +
               {
         
     | 
| 
      
 106 
     | 
    
         
            +
                  enum { value = true };
         
     | 
| 
      
 107 
     | 
    
         
            +
               };
         
     | 
| 
      
 108 
     | 
    
         
            +
             
     | 
| 
      
 109 
     | 
    
         
            +
               LZHAM_DEFINE_BITWISE_COPYABLE(empty_type);
         
     | 
| 
      
 110 
     | 
    
         
            +
               LZHAM_DEFINE_BITWISE_MOVABLE(empty_type);
         
     | 
| 
      
 111 
     | 
    
         
            +
             
     | 
| 
      
 112 
     | 
    
         
            +
               namespace helpers
         
     | 
| 
      
 113 
     | 
    
         
            +
               {
         
     | 
| 
      
 114 
     | 
    
         
            +
                  template <typename T>
         
     | 
| 
      
 115 
     | 
    
         
            +
                  inline void construct_array(T* p, uint n)
         
     | 
| 
      
 116 
     | 
    
         
            +
                  {
         
     | 
| 
      
 117 
     | 
    
         
            +
                     if (LZHAM_IS_SCALAR_TYPE(T))
         
     | 
| 
      
 118 
     | 
    
         
            +
                     {
         
     | 
| 
      
 119 
     | 
    
         
            +
                        memset(p, 0, sizeof(T) * n);
         
     | 
| 
      
 120 
     | 
    
         
            +
                     }
         
     | 
| 
      
 121 
     | 
    
         
            +
                     else
         
     | 
| 
      
 122 
     | 
    
         
            +
                     {
         
     | 
| 
      
 123 
     | 
    
         
            +
                        T* q = p + n;
         
     | 
| 
      
 124 
     | 
    
         
            +
                        for ( ; p != q; ++p)
         
     | 
| 
      
 125 
     | 
    
         
            +
                           new (static_cast<void*>(p)) T;
         
     | 
| 
      
 126 
     | 
    
         
            +
                     }
         
     | 
| 
      
 127 
     | 
    
         
            +
                  }
         
     | 
| 
      
 128 
     | 
    
         
            +
             
     | 
| 
      
 129 
     | 
    
         
            +
                  template <typename T>
         
     | 
| 
      
 130 
     | 
    
         
            +
                  inline void destruct_array(T* p, uint n)
         
     | 
| 
      
 131 
     | 
    
         
            +
                  {
         
     | 
| 
      
 132 
     | 
    
         
            +
                     if ( LZHAM_HAS_DESTRUCTOR(T) )
         
     | 
| 
      
 133 
     | 
    
         
            +
                     {
         
     | 
| 
      
 134 
     | 
    
         
            +
                        T* q = p + n;
         
     | 
| 
      
 135 
     | 
    
         
            +
                        for ( ; p != q; ++p)
         
     | 
| 
      
 136 
     | 
    
         
            +
                           p->~T();
         
     | 
| 
      
 137 
     | 
    
         
            +
                     }
         
     | 
| 
      
 138 
     | 
    
         
            +
                  }
         
     | 
| 
      
 139 
     | 
    
         
            +
               }
         
     | 
| 
      
 140 
     | 
    
         
            +
             
     | 
| 
      
 141 
     | 
    
         
            +
            } // namespace lzham
         
     | 
| 
         @@ -0,0 +1,97 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            // File: types.h
         
     | 
| 
      
 2 
     | 
    
         
            +
            // See Copyright Notice and license at the end of include/lzham.h
         
     | 
| 
      
 3 
     | 
    
         
            +
            #pragma once
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
            // TODO
         
     | 
| 
      
 6 
     | 
    
         
            +
            #if defined(__APPLE__) || defined(__FreeBSD__) || defined(__NetBSD__)
         
     | 
| 
      
 7 
     | 
    
         
            +
               #undef INT8_MIN
         
     | 
| 
      
 8 
     | 
    
         
            +
               #undef INT8_MAX
         
     | 
| 
      
 9 
     | 
    
         
            +
               #undef UINT8_MIN
         
     | 
| 
      
 10 
     | 
    
         
            +
               #undef UINT8_MAX
         
     | 
| 
      
 11 
     | 
    
         
            +
             
     | 
| 
      
 12 
     | 
    
         
            +
               #undef INT16_MIN
         
     | 
| 
      
 13 
     | 
    
         
            +
               #undef INT16_MAX
         
     | 
| 
      
 14 
     | 
    
         
            +
               #undef UINT16_MIN
         
     | 
| 
      
 15 
     | 
    
         
            +
               #undef UINT16_MAX
         
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
      
 17 
     | 
    
         
            +
               #undef INT32_MIN
         
     | 
| 
      
 18 
     | 
    
         
            +
               #undef INT32_MAX
         
     | 
| 
      
 19 
     | 
    
         
            +
               #undef UINT32_MIN
         
     | 
| 
      
 20 
     | 
    
         
            +
               #undef UINT32_MAX
         
     | 
| 
      
 21 
     | 
    
         
            +
             
     | 
| 
      
 22 
     | 
    
         
            +
               #undef INT64_MIN
         
     | 
| 
      
 23 
     | 
    
         
            +
               #undef INT64_MAX
         
     | 
| 
      
 24 
     | 
    
         
            +
               #undef UINT64_MIN
         
     | 
| 
      
 25 
     | 
    
         
            +
               #undef UINT64_MAX
         
     | 
| 
      
 26 
     | 
    
         
            +
            #endif
         
     | 
| 
      
 27 
     | 
    
         
            +
             
     | 
| 
      
 28 
     | 
    
         
            +
            namespace lzham
         
     | 
| 
      
 29 
     | 
    
         
            +
            {
         
     | 
| 
      
 30 
     | 
    
         
            +
               typedef unsigned char      uint8;
         
     | 
| 
      
 31 
     | 
    
         
            +
               typedef signed char        int8;
         
     | 
| 
      
 32 
     | 
    
         
            +
               typedef unsigned char      uint8;
         
     | 
| 
      
 33 
     | 
    
         
            +
               typedef unsigned short     uint16;
         
     | 
| 
      
 34 
     | 
    
         
            +
               typedef signed short       int16;
         
     | 
| 
      
 35 
     | 
    
         
            +
               typedef unsigned int       uint32;
         
     | 
| 
      
 36 
     | 
    
         
            +
               typedef uint32             uint;
         
     | 
| 
      
 37 
     | 
    
         
            +
               typedef signed int         int32;
         
     | 
| 
      
 38 
     | 
    
         
            +
             
     | 
| 
      
 39 
     | 
    
         
            +
               #ifdef _MSC_VER
         
     | 
| 
      
 40 
     | 
    
         
            +
                  typedef unsigned __int64      uint64;
         
     | 
| 
      
 41 
     | 
    
         
            +
                  typedef signed __int64        int64;
         
     | 
| 
      
 42 
     | 
    
         
            +
               #else
         
     | 
| 
      
 43 
     | 
    
         
            +
                  typedef unsigned long long    uint64;
         
     | 
| 
      
 44 
     | 
    
         
            +
                  typedef long long             int64;
         
     | 
| 
      
 45 
     | 
    
         
            +
               #endif
         
     | 
| 
      
 46 
     | 
    
         
            +
             
     | 
| 
      
 47 
     | 
    
         
            +
               const uint8  UINT8_MIN  = 0;
         
     | 
| 
      
 48 
     | 
    
         
            +
               const uint8  UINT8_MAX  = 0xFFU;
         
     | 
| 
      
 49 
     | 
    
         
            +
               const uint16 UINT16_MIN = 0;
         
     | 
| 
      
 50 
     | 
    
         
            +
               const uint16 UINT16_MAX = 0xFFFFU;
         
     | 
| 
      
 51 
     | 
    
         
            +
               const uint32 UINT32_MIN = 0;
         
     | 
| 
      
 52 
     | 
    
         
            +
               const uint32 UINT32_MAX = 0xFFFFFFFFU;
         
     | 
| 
      
 53 
     | 
    
         
            +
               const uint64 UINT64_MIN = 0;
         
     | 
| 
      
 54 
     | 
    
         
            +
               const uint64 UINT64_MAX = 0xFFFFFFFFFFFFFFFFULL;    //0xFFFFFFFFFFFFFFFFui64;
         
     | 
| 
      
 55 
     | 
    
         
            +
             
     | 
| 
      
 56 
     | 
    
         
            +
               const int8  INT8_MIN  = -128;
         
     | 
| 
      
 57 
     | 
    
         
            +
               const int8  INT8_MAX  = 127;
         
     | 
| 
      
 58 
     | 
    
         
            +
               const int16 INT16_MIN = -32768;
         
     | 
| 
      
 59 
     | 
    
         
            +
               const int16 INT16_MAX = 32767;
         
     | 
| 
      
 60 
     | 
    
         
            +
               const int32 INT32_MIN = (-2147483647 - 1);
         
     | 
| 
      
 61 
     | 
    
         
            +
               const int32 INT32_MAX = 2147483647;
         
     | 
| 
      
 62 
     | 
    
         
            +
               const int64 INT64_MIN = (int64)0x8000000000000000ULL; //(-9223372036854775807i64 - 1);
         
     | 
| 
      
 63 
     | 
    
         
            +
               const int64 INT64_MAX = (int64)0x7FFFFFFFFFFFFFFFULL; //9223372036854775807i64;
         
     | 
| 
      
 64 
     | 
    
         
            +
             
     | 
| 
      
 65 
     | 
    
         
            +
            #if LZHAM_64BIT_POINTERS
         
     | 
| 
      
 66 
     | 
    
         
            +
               typedef uint64 uint_ptr;
         
     | 
| 
      
 67 
     | 
    
         
            +
               typedef uint64 uint32_ptr;
         
     | 
| 
      
 68 
     | 
    
         
            +
               typedef int64 signed_size_t;
         
     | 
| 
      
 69 
     | 
    
         
            +
               typedef uint64 ptr_bits_t;
         
     | 
| 
      
 70 
     | 
    
         
            +
               const ptr_bits_t PTR_BITS_XOR = 0xDB0DD4415C87DCF7ULL;
         
     | 
| 
      
 71 
     | 
    
         
            +
            #else
         
     | 
| 
      
 72 
     | 
    
         
            +
               typedef unsigned int uint_ptr;
         
     | 
| 
      
 73 
     | 
    
         
            +
               typedef unsigned int uint32_ptr;
         
     | 
| 
      
 74 
     | 
    
         
            +
               typedef signed int signed_size_t;
         
     | 
| 
      
 75 
     | 
    
         
            +
               typedef uint32 ptr_bits_t;
         
     | 
| 
      
 76 
     | 
    
         
            +
               const ptr_bits_t PTR_BITS_XOR = 0x5C87DCF7UL;
         
     | 
| 
      
 77 
     | 
    
         
            +
            #endif
         
     | 
| 
      
 78 
     | 
    
         
            +
               
         
     | 
| 
      
 79 
     | 
    
         
            +
               enum
         
     | 
| 
      
 80 
     | 
    
         
            +
               {
         
     | 
| 
      
 81 
     | 
    
         
            +
                  cInvalidIndex = -1
         
     | 
| 
      
 82 
     | 
    
         
            +
               };
         
     | 
| 
      
 83 
     | 
    
         
            +
             
     | 
| 
      
 84 
     | 
    
         
            +
               const uint cIntBits = sizeof(uint) * CHAR_BIT;
         
     | 
| 
      
 85 
     | 
    
         
            +
             
     | 
| 
      
 86 
     | 
    
         
            +
               template<typename T> struct int_traits { enum { cMin = INT_MIN, cMax = INT_MAX, cSigned = true }; };
         
     | 
| 
      
 87 
     | 
    
         
            +
               template<> struct int_traits<int8> { enum { cMin = INT8_MIN, cMax = INT8_MAX, cSigned = true }; };
         
     | 
| 
      
 88 
     | 
    
         
            +
               template<> struct int_traits<int16> { enum { cMin = INT16_MIN, cMax = INT16_MAX, cSigned = true }; };
         
     | 
| 
      
 89 
     | 
    
         
            +
               template<> struct int_traits<int32> { enum { cMin = INT32_MIN, cMax = INT32_MAX, cSigned = true }; };
         
     | 
| 
      
 90 
     | 
    
         
            +
             
     | 
| 
      
 91 
     | 
    
         
            +
               template<> struct int_traits<uint> { enum { cMin = 0, cMax = UINT_MAX, cSigned = false }; };
         
     | 
| 
      
 92 
     | 
    
         
            +
               template<> struct int_traits<uint8> { enum { cMin = 0, cMax = UINT8_MAX, cSigned = false }; };
         
     | 
| 
      
 93 
     | 
    
         
            +
               template<> struct int_traits<uint16> { enum { cMin = 0, cMax = UINT16_MAX, cSigned = false }; };
         
     | 
| 
      
 94 
     | 
    
         
            +
             
     | 
| 
      
 95 
     | 
    
         
            +
               struct empty_type { };
         
     | 
| 
      
 96 
     | 
    
         
            +
             
     | 
| 
      
 97 
     | 
    
         
            +
            } // namespace lzham
         
     | 
| 
         @@ -0,0 +1,58 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            // File: lzham_utils.h
         
     | 
| 
      
 2 
     | 
    
         
            +
            // See Copyright Notice and license at the end of include/lzham.h
         
     | 
| 
      
 3 
     | 
    
         
            +
            #pragma once
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
            #define LZHAM_GET_ALIGNMENT(v) ((!sizeof(v)) ? 1 : (__alignof(v) ? __alignof(v) : sizeof(uint32))) 
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
            #define LZHAM_MIN(a, b) (((a) < (b)) ? (a) : (b))
         
     | 
| 
      
 8 
     | 
    
         
            +
            #define LZHAM_MAX(a, b) (((a) < (b)) ? (b) : (a))
         
     | 
| 
      
 9 
     | 
    
         
            +
             
     | 
| 
      
 10 
     | 
    
         
            +
            template<class T, size_t N> T decay_array_to_subtype(T (&a)[N]);
         
     | 
| 
      
 11 
     | 
    
         
            +
            #define LZHAM_ARRAY_SIZE(X) (sizeof(X) / sizeof(decay_array_to_subtype(X)))
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
            namespace lzham
         
     | 
| 
      
 14 
     | 
    
         
            +
            {
         
     | 
| 
      
 15 
     | 
    
         
            +
               namespace utils
         
     | 
| 
      
 16 
     | 
    
         
            +
               {
         
     | 
| 
      
 17 
     | 
    
         
            +
                  template<typename T> inline void swap(T& l, T& r)
         
     | 
| 
      
 18 
     | 
    
         
            +
                  {
         
     | 
| 
      
 19 
     | 
    
         
            +
                     T temp(l);
         
     | 
| 
      
 20 
     | 
    
         
            +
                     l = r;
         
     | 
| 
      
 21 
     | 
    
         
            +
                     r = temp;
         
     | 
| 
      
 22 
     | 
    
         
            +
                  }
         
     | 
| 
      
 23 
     | 
    
         
            +
                  
         
     | 
| 
      
 24 
     | 
    
         
            +
                  template<typename T> inline void zero_object(T& obj)
         
     | 
| 
      
 25 
     | 
    
         
            +
                  {
         
     | 
| 
      
 26 
     | 
    
         
            +
                     memset(&obj, 0, sizeof(obj));
         
     | 
| 
      
 27 
     | 
    
         
            +
                  }
         
     | 
| 
      
 28 
     | 
    
         
            +
                              
         
     | 
| 
      
 29 
     | 
    
         
            +
                  static inline uint32 swap32(uint32 x) { return ((x << 24U) | ((x << 8U) & 0x00FF0000U) | ((x >> 8U) & 0x0000FF00U) | (x >> 24U)); }
         
     | 
| 
      
 30 
     | 
    
         
            +
                  
         
     | 
| 
      
 31 
     | 
    
         
            +
                  inline uint count_leading_zeros16(uint v)
         
     | 
| 
      
 32 
     | 
    
         
            +
                  {
         
     | 
| 
      
 33 
     | 
    
         
            +
                     LZHAM_ASSERT(v < 0x10000);
         
     | 
| 
      
 34 
     | 
    
         
            +
                     
         
     | 
| 
      
 35 
     | 
    
         
            +
                     uint temp;
         
     | 
| 
      
 36 
     | 
    
         
            +
                     uint n = 16;
         
     | 
| 
      
 37 
     | 
    
         
            +
                     
         
     | 
| 
      
 38 
     | 
    
         
            +
                     temp = v >> 8;
         
     | 
| 
      
 39 
     | 
    
         
            +
                     if (temp) { n -=  8; v = temp; }
         
     | 
| 
      
 40 
     | 
    
         
            +
             
     | 
| 
      
 41 
     | 
    
         
            +
                     temp = v >> 4;
         
     | 
| 
      
 42 
     | 
    
         
            +
                     if (temp) { n -=  4; v = temp; }
         
     | 
| 
      
 43 
     | 
    
         
            +
             
     | 
| 
      
 44 
     | 
    
         
            +
                     temp = v >> 2;
         
     | 
| 
      
 45 
     | 
    
         
            +
                     if (temp) { n -=  2; v = temp; }
         
     | 
| 
      
 46 
     | 
    
         
            +
             
     | 
| 
      
 47 
     | 
    
         
            +
                     temp = v >> 1;
         
     | 
| 
      
 48 
     | 
    
         
            +
                     if (temp) { n -=  1; v = temp; }
         
     | 
| 
      
 49 
     | 
    
         
            +
             
     | 
| 
      
 50 
     | 
    
         
            +
                     if (v & 1) n--;
         
     | 
| 
      
 51 
     | 
    
         
            +
             
     | 
| 
      
 52 
     | 
    
         
            +
                     return n;
         
     | 
| 
      
 53 
     | 
    
         
            +
                  }
         
     | 
| 
      
 54 
     | 
    
         
            +
                  
         
     | 
| 
      
 55 
     | 
    
         
            +
               }   // namespace utils
         
     | 
| 
      
 56 
     | 
    
         
            +
                     
         
     | 
| 
      
 57 
     | 
    
         
            +
            } // namespace lzham
         
     | 
| 
      
 58 
     | 
    
         
            +
             
     | 
| 
         @@ -0,0 +1,75 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            // File: lzham_vector.cpp
         
     | 
| 
      
 2 
     | 
    
         
            +
            // See Copyright Notice and license at the end of include/lzham.h
         
     | 
| 
      
 3 
     | 
    
         
            +
            #include "lzham_core.h"
         
     | 
| 
      
 4 
     | 
    
         
            +
            #include "lzham_vector.h"
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
            namespace lzham
         
     | 
| 
      
 7 
     | 
    
         
            +
            {
         
     | 
| 
      
 8 
     | 
    
         
            +
               bool elemental_vector::increase_capacity(uint min_new_capacity, bool grow_hint, uint element_size, object_mover pMover, bool nofail)
         
     | 
| 
      
 9 
     | 
    
         
            +
               {
         
     | 
| 
      
 10 
     | 
    
         
            +
                  LZHAM_ASSERT(m_size <= m_capacity);
         
     | 
| 
      
 11 
     | 
    
         
            +
                  
         
     | 
| 
      
 12 
     | 
    
         
            +
            #if LZHAM_64BIT_POINTERS
         
     | 
| 
      
 13 
     | 
    
         
            +
                  LZHAM_ASSUME(sizeof(void*) == sizeof(uint64));
         
     | 
| 
      
 14 
     | 
    
         
            +
                  LZHAM_ASSERT(min_new_capacity < (0x400000000ULL / element_size));
         
     | 
| 
      
 15 
     | 
    
         
            +
            #else      
         
     | 
| 
      
 16 
     | 
    
         
            +
                  LZHAM_ASSUME(sizeof(void*) == sizeof(uint32));
         
     | 
| 
      
 17 
     | 
    
         
            +
                  LZHAM_ASSERT(min_new_capacity < (0x7FFF0000U / element_size));
         
     | 
| 
      
 18 
     | 
    
         
            +
            #endif      
         
     | 
| 
      
 19 
     | 
    
         
            +
             
     | 
| 
      
 20 
     | 
    
         
            +
                  if (m_capacity >= min_new_capacity)
         
     | 
| 
      
 21 
     | 
    
         
            +
                     return true;
         
     | 
| 
      
 22 
     | 
    
         
            +
             
     | 
| 
      
 23 
     | 
    
         
            +
                  // new_capacity must be 64-bit when compiling on x64.
         
     | 
| 
      
 24 
     | 
    
         
            +
            		size_t new_capacity = (size_t)min_new_capacity;
         
     | 
| 
      
 25 
     | 
    
         
            +
                  if ((grow_hint) && (!math::is_power_of_2(static_cast<uint64>(new_capacity))))
         
     | 
| 
      
 26 
     | 
    
         
            +
                     new_capacity = static_cast<uint>(math::next_pow2(static_cast<uint64>(new_capacity)));
         
     | 
| 
      
 27 
     | 
    
         
            +
             
     | 
| 
      
 28 
     | 
    
         
            +
                  LZHAM_ASSERT(new_capacity && (new_capacity > m_capacity));
         
     | 
| 
      
 29 
     | 
    
         
            +
             
     | 
| 
      
 30 
     | 
    
         
            +
                  const size_t desired_size = element_size * new_capacity;
         
     | 
| 
      
 31 
     | 
    
         
            +
                  size_t actual_size;
         
     | 
| 
      
 32 
     | 
    
         
            +
                  if (!pMover)
         
     | 
| 
      
 33 
     | 
    
         
            +
                  {
         
     | 
| 
      
 34 
     | 
    
         
            +
                     void* new_p = lzham_realloc(m_p, desired_size, &actual_size, true);
         
     | 
| 
      
 35 
     | 
    
         
            +
                     if (!new_p)
         
     | 
| 
      
 36 
     | 
    
         
            +
                     {
         
     | 
| 
      
 37 
     | 
    
         
            +
                        if (nofail)
         
     | 
| 
      
 38 
     | 
    
         
            +
                           return false;
         
     | 
| 
      
 39 
     | 
    
         
            +
                           
         
     | 
| 
      
 40 
     | 
    
         
            +
                        char buf[256];
         
     | 
| 
      
 41 
     | 
    
         
            +
                        sprintf_s(buf, sizeof(buf), "vector: lzham_realloc() failed allocating %u bytes", desired_size);
         
     | 
| 
      
 42 
     | 
    
         
            +
                        LZHAM_FAIL(buf);
         
     | 
| 
      
 43 
     | 
    
         
            +
                     }
         
     | 
| 
      
 44 
     | 
    
         
            +
                     m_p = new_p;
         
     | 
| 
      
 45 
     | 
    
         
            +
                  }
         
     | 
| 
      
 46 
     | 
    
         
            +
                  else
         
     | 
| 
      
 47 
     | 
    
         
            +
                  {
         
     | 
| 
      
 48 
     | 
    
         
            +
                     void* new_p = lzham_malloc(desired_size, &actual_size);
         
     | 
| 
      
 49 
     | 
    
         
            +
                     if (!new_p)
         
     | 
| 
      
 50 
     | 
    
         
            +
                     {
         
     | 
| 
      
 51 
     | 
    
         
            +
                        if (nofail)
         
     | 
| 
      
 52 
     | 
    
         
            +
                           return false;
         
     | 
| 
      
 53 
     | 
    
         
            +
                           
         
     | 
| 
      
 54 
     | 
    
         
            +
                        char buf[256];
         
     | 
| 
      
 55 
     | 
    
         
            +
                        sprintf_s(buf, sizeof(buf), "vector: lzham_malloc() failed allocating %u bytes", desired_size);
         
     | 
| 
      
 56 
     | 
    
         
            +
                        LZHAM_FAIL(buf);
         
     | 
| 
      
 57 
     | 
    
         
            +
                     }
         
     | 
| 
      
 58 
     | 
    
         
            +
                     
         
     | 
| 
      
 59 
     | 
    
         
            +
                     (*pMover)(new_p, m_p, m_size);
         
     | 
| 
      
 60 
     | 
    
         
            +
                     
         
     | 
| 
      
 61 
     | 
    
         
            +
                     if (m_p)
         
     | 
| 
      
 62 
     | 
    
         
            +
                        lzham_free(m_p);
         
     | 
| 
      
 63 
     | 
    
         
            +
             
     | 
| 
      
 64 
     | 
    
         
            +
                     m_p = new_p;
         
     | 
| 
      
 65 
     | 
    
         
            +
                  }            
         
     | 
| 
      
 66 
     | 
    
         
            +
                  
         
     | 
| 
      
 67 
     | 
    
         
            +
                  if (actual_size > desired_size)
         
     | 
| 
      
 68 
     | 
    
         
            +
                     m_capacity = static_cast<uint>(actual_size / element_size);
         
     | 
| 
      
 69 
     | 
    
         
            +
                  else
         
     | 
| 
      
 70 
     | 
    
         
            +
                     m_capacity = static_cast<uint>(new_capacity);
         
     | 
| 
      
 71 
     | 
    
         
            +
                
         
     | 
| 
      
 72 
     | 
    
         
            +
                  return true;
         
     | 
| 
      
 73 
     | 
    
         
            +
               }
         
     | 
| 
      
 74 
     | 
    
         
            +
             
     | 
| 
      
 75 
     | 
    
         
            +
            } // namespace lzham
         
     |