Much code can be clarified by using C++ STL-like algorithms. Not
all uses of these algorithms are listed below, only the ones where
the change to an algorithm was the only change of interest.
* frequencies.q: Remove a lot of old #if'd out code at the end.
(internal_cmd_frequencies) Use calc() instead of calc_no_weight()
or calc_weight(). Initialize percentile_values.
(calc) New function based on calc_weight() from frequencies.g.
(precalc) Use hash functions.
(static var comparison_func) Removed.
(static var comparison_param) Removed.
(comparison_helper) Removed.
(get_freq_comparator) New function.
(not_missing) New function.
(add_freq) Removed.
(postprocess_freq_tab) Use hash table functions, algorithms,
get_freq_comparator(). Rewrite.
(cleanup_freq_tab) Rephrase.
(add_percentile) Clean up spacing.
(hash_value_numeric) New function.
(hash_value_alpha) New function.
(compare_value_numeric_a) Rewrite.
(compare_value_alpha_a) Rewrite.
(compare_value_numeric_d) Rewrite.
(compare_value_alpha_d) Rewrite.
(compare_freq_numeric_a) Rewrite.
(compare_freq_alpha_a) Rewrite.
(compare_freq_numeric_d) Rewrite.
(compare_freq_alpha_d) Rewrite.
(calc_stats) Clean up mode, percentiles, max.
(dump_statistics) Clean up spacing.
* frequencies.g: Removed.
* var.h: (struct freq_tab) Change `data' to hash table.
Fri Dec 19 14:15:46 2003 Ben Pfaff <blp@gnu.org>
* file-handle.h: Remove declaration of global variable `files',
which wasn't used anywhere.
* sfm-read.c: [linux] (bswap_int32) Drop ntohl() non-portable
version.
* temporary.c: [0] (display_tree) Removed.
Fri Dec 19 14:13:04 2003 Ben Pfaff <blp@gnu.org>
Implement a new random number generator based on the alleged RC4
algorithm.
* expr-evl.c: (expr_evaluate) Use rng_get_double_normal() instead
of rand_normal().
* random.c: [!HAVE_GOOD_RANDOM] (real_rand) Removed.
[!HAVE_GOOD_RANDOM] (real_srand) Removed.
(macro k) Removed.
(static var V[]) Removed.
(static var Y) Removed.
(static var X2) Removed.
(setup_randomize) Removed.
(shuffle) Removed.
(rand_uniform) Removed.
(rand_normal) Removed.
(struct rng) New structure.
(rng_create) New function.
(rng_destroy) New function.
(swap_byte) New static function.
(rng_seed) New function.
(rng_get_bytes) New function.
(rng_get_int) New function.
(rng_get_unsigned) New function.
(rng_get_double) New function.
(rng_get_double_normal) New function.
(pspp_rng) New function.
* random.h: Sync up to random.c.
* sample.c: (struct sample_trns) Make `frac' unsigned and a
fraction of UINT_MAX, not 65536.
(cmd_sample) Use rng_get_unsigned(), rng_get_double(), UINT_MAX
fraction.
* vfm.c: (open_active_file) No need to call setup_randomize() any
longer.
Fri Dec 19 12:05:56 2003 Ben Pfaff <blp@gnu.org>
Change dictionary name indexes to use hash tables instead of AVL
trees.
* crosstabs.q: (free_var_dict) Use hash tables.
(crs_custom_tables) Ditto.
(calc_general) Ditto.
(compare_table_entry) Rewrite.
(enum_var_values) Reorder parameters. All references updated.
Rewrite.
* get.c: (rename_variable) Use hash tables.
(mtf_merge_dictionary) Ditto.
* glob.c: (init_glob) Use hash tables.
(cmp_variable) Removed.
* means.q: (mns_custom_tables) Use hash tables.
* modify-vars.c: (rearrange_dict) Use hash tables.
* rename-vars.c: (cmd_rename_variables) Use hash tables.
* sfm-read.c: (read_header) Use hash tables.
(read_variables) Ditto.
* temporary.c: (new_dictionary) Use hash tables.
(save_dictionary) Ditto.
(restore_dictionary) Ditto.
* var.h: (struct dictionary) Change AVL tree `var_by_name' into
hash table `name_tab'.
John Darrington [Sat, 13 Dec 2003 11:18:31 +0000 (11:18 +0000)]
Fixed intl/ and some tests, so that the project can be built and tested
from outside of the source tree (or at least it will when some bugs are
squashed)
Ben Pfaff [Sat, 13 Dec 2003 08:11:55 +0000 (08:11 +0000)]
Fri Dec 12 23:54:37 2003 Ben Pfaff <blp@gnu.org>
* autorecode.c: (recode) Replace stupid use of memcpy() by
memberwise copy.
(hash_alpha_value) Use hsh_hash_bytes(). Get rid of nasty casts.
(hash_numeric_value) Ditto.
(autorecode_proc_func) pool_strdup() was wrong here because the
source string was not null-terminated. Use new pool_strndup()
instead.
* crosstabs.q: (enum_var_values) Remove superfluous and bizarre
use of hsh_iterator_init().
* data-in.c: (parse_N) Initialize i->v->f.
* flip.c: (cmd_flip) Use memmove(), not memcpy(), to copy
overlapping arrays.
* groff-font.c: Use power-of-2 hash table sizes, not prime.
(groff_read_font) Don't call hsh_next_prime(). Don't call
fclose(NULL).
(static var hash) Remove `size_p', `max_used' members.
(font_char_name_to_index) Don't call hsh_next_prime(). Use
hsh_hash_string() instead of hashpjw(), & instead of %.
(default_font) Don't call hsh_next_prime().
* pool.c: (pool_strndup) New function.
(pool_strdup) Reimplement in terms of pool_strndup.
* postscript.c: (hash_font_entry) Use hsh_hash_string(). Get rid
of nasty casts.
(hash_ps_encoding) Use hsh_hash_string().
(hash_ps_combo) Use hsh_hash_string(), hsh_hash_int().
(hash_filename2font) Use hsh_hash_string().
* som.c: Add #include <stdlib.h>.
* tab.c: (tab_destroy) Don't set t->container after freeing `t'
(by destroying its pool).
Fri Dec 12 23:18:59 2003 Ben Pfaff <blp@gnu.org>
Miscellaneous hash table code cleanup:
* hash.h: (struct hsh_table) Moved into hash.c.
(hsh_count) Ditto, and transformed into function.
(hsh_compare_func) New typedef, used for defining otherwise-long
function types here and in hash.c
(hsh_hash_func) Ditto.
(hsh_free_func) Ditto.
* hash.c: (struct hsh_table) Renamed `n' to `used', `m' to `size',
`table' to `entries'. Removed `mp'. All references updated.
(hsh_clear) Don't shrink entries array; if the hash was this big
once, it probably will be again.
(hsh_rehash) Made static.
(force_hsh_insert) Renamed hsh_force_insert.
(force_hsh_find) Renamed hsh_force_find.
Made hash table sizes powers of 2, because that's fine with any
reasonable hash function and because taking a power-of-2 modulus
is faster than any other:
(hsh_prime_tab) Removed;
(hsh_next_prime) Ditto.
(next_power_of_2) New function.
(hsh_create) Use next_power_of_2.
(hsh_rehash) Use & instead of %.
Cleaned up hsh_sort:
(internal_comparison_fn) Removed.
(sort_nulls_last) New function.
(hsh_sort) Removed second parameter, switched to using the new
quicksort() function from quicksort.h to avoid using nasty need
for static variables with qsort(). All references updated.
Changed the hash functions offered, because there are better hash
functions than the ones we had, and cleaned up the names to boot:
* hash.c: (hashpjw_d) Removed.
(hashpjw) Ditto.
(hsh_hash_bytes) New function.
(hsh_hash_string) New function.
(hsh_hash_int) New function.
* hash.c: (hsh_foreach) Removed. All references updated to use
hsh_first/hsh_next instead.
(hsh_first) New function. Notably, unlike hsh_foreach() it does
not treat a null pointer as an empty hash table.
(hsh_next) New function.
Made deletion possible, though slow:
* hash.c: (locate_matching_entry) New function.
(hsh_find) Use locate_matching_entry().
(hsh_delete) New function also using locate_matching_entry().
(hsh_force_delete) New function.
Fri Dec 12 23:16:10 2003 Ben Pfaff <blp@gnu.org>
* quicksort.c: New file implementing a sort routine with a
interface better than qsort() because it passes a user-provided
parameter to the sort routine.
Ben Pfaff [Thu, 11 Dec 2003 06:17:20 +0000 (06:17 +0000)]
* glob.c: Add #include <stdio.h> the readline.h #include, which
fixes problems for some readline versions that refer to FILE but
don't #include <stdio.h> themselves.