/** * Initiliazes the fields of the StringArray and its parent class * PersistentStructure. Creates a null filled string array of size * $this->string_array_size to stored data in. * * @param string $fname the name of the file to store data persistently in * @param int $num_values the number of items the StringArray will store * @param int $data_size the size in bytes of a single item * @param int $save_frequency how often the StringArray should be stored to * disk */ function __construct($fname, $num_values, $data_size, $save_frequency = self::DEFAULT_SAVE_FREQUENCY) { $this->num_values = $num_values; $this->data_size = $data_size; $this->string_array_size = $num_values * $data_size; $this->string_array = pack("x" . $this->string_array_size); parent::__construct($fname, $save_frequency); }
/** * Initializes the fields of the BloomFilter and its base * PersistentStructure. * * @param string $fname name of the file to store the BloomFilter data in * @param int $num_values the maximum number of values that will be stored * in the BloomFilter. Filter will be sized so the odds of a false * positive are roughly one over this value * @param int $save_frequency how often to store the BloomFilter to disk */ function __construct($fname, $num_values, $save_frequency = self::DEFAULT_SAVE_FREQUENCY) { $log2 = log(2); $this->num_keys = ceil(log($num_values) / $log2); $this->filter_size = ceil($this->num_keys * $num_values / $log2); $mem_before = memory_get_usage(true); $this->filter = pack("x" . ceil(0.125 * $this->filter_size)); // 1/8 =.125 = num bits/bytes, want to make things floats $mem = memory_get_usage(true) - $mem_before; parent::__construct($fname, $save_frequency); }