X-Git-Url: https://wimlib.net/git/?a=blobdiff_plain;f=src%2Flz_mf.c;h=ee7c80d89eac39529c00dd821494104d475bcd2c;hb=55a72fc546978ea0502ef0d0eba73ffd6c3ee785;hp=bb954275cbf274263a215701ce94f92066dfb8ad;hpb=4dd45340f9fe3a533e0f1a9d6b79f8118e45ca2a;p=wimlib diff --git a/src/lz_mf.c b/src/lz_mf.c index bb954275..ee7c80d8 100644 --- a/src/lz_mf.c +++ b/src/lz_mf.c @@ -39,34 +39,16 @@ /* Available match-finding algorithms. */ static const struct lz_mf_ops *mf_ops[] = { - [LZ_MF_NULL] = &lz_null_ops, - [LZ_MF_BRUTE_FORCE] = &lz_brute_force_ops, - [LZ_MF_HASH_CHAINS] = &lz_hash_chains_ops, - [LZ_MF_BINARY_TREES] = &lz_binary_trees_ops, [LZ_MF_LCP_INTERVAL_TREE] = &lz_lcp_interval_tree_ops, [LZ_MF_LINKED_SUFFIX_ARRAY] = &lz_linked_suffix_array_ops, }; -/* - * Automatically select a match-finding algorithm to use, in the case that the - * user did not specify one. - */ static const struct lz_mf_ops * -select_mf_ops(enum lz_mf_algo algorithm, u32 max_window_size) +get_mf_ops(enum lz_mf_algo algorithm) { - if (algorithm == LZ_MF_DEFAULT) { - if (max_window_size <= 32768) - algorithm = LZ_MF_HASH_CHAINS; - else if (max_window_size <= 2097152) - algorithm = LZ_MF_BINARY_TREES; - else if (max_window_size <= 33554432) - algorithm = LZ_MF_LCP_INTERVAL_TREE; - else - algorithm = LZ_MF_LINKED_SUFFIX_ARRAY; - } - if ((int)algorithm < 0 || (int)algorithm >= ARRAY_LEN(mf_ops)) + if ((unsigned int)algorithm >= ARRAY_LEN(mf_ops)) return NULL; - return mf_ops[(int)algorithm]; + return mf_ops[(unsigned int)algorithm]; } /* @@ -84,7 +66,7 @@ lz_mf_get_needed_memory(enum lz_mf_algo algorithm, u32 max_window_size) { const struct lz_mf_ops *ops; - ops = select_mf_ops(algorithm, max_window_size); + ops = get_mf_ops(algorithm); if (!ops) return 0; return ops->struct_size + ops->get_needed_memory(max_window_size); @@ -98,8 +80,8 @@ lz_mf_params_valid(const struct lz_mf_params *params) { const struct lz_mf_ops *ops; - /* Require that a valid algorithm, or LZ_MF_DEFAULT, be specified. */ - ops = select_mf_ops(params->algorithm, params->max_window_size); + /* Require that a valid algorithm be specified. */ + ops = get_mf_ops(params->algorithm); if (!ops) return false; @@ -166,7 +148,7 @@ lz_mf_alloc(const struct lz_mf_params *params) /* Get the match-finder operations structure. Since we just validated * the parameters, this is guaranteed to return a valid structure. */ - ops = select_mf_ops(params->algorithm, params->max_window_size); + ops = get_mf_ops(params->algorithm); LZ_ASSERT(ops != NULL); /* Allocate memory for the match-finder structure. */