--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * An interface for Indexable classes
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2012 Core Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.org
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+interface Indexable??? extends Indexable {
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * An interface for Indexable classes
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2012 Core Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.org
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+interface Indexable extends FrameworkInterface {
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * An interface for Indexable stack classes
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2012 Core Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.org
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+interface IndexableStack extends Indexable {
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A factory class for file-based stack indexes
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2012 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.org
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+class FileStackIndexFactory extends ObjectFactory {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Returns a singleton (registry-based) StackableFile instance
+ *
+ * @param $stackName Name of the stack's file
+ * @return $indexInstance An instance of a IndexableStack class
+ */
+ public static final function createFileStackIndexInstance ($fileName) {
+ // Call parent factory
+ $indexInstance self::createObjectByConfiguredName('file_stack_index_class', array($fileName));
+
+ // Return the instance
+ return $indexInstance;
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A ??? index class
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2012 Core Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.org
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+class ???Index extends BaseIndex implements Indexable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this Index class and prepares it for usage
+ *
+ * @param $fileName Name of the file stack to create an index file for
+ * @return $indexInstance An instance of this Index class
+ */
+ public final static function create???Index ($fileName) {
+ // Get a new instance
+ $indexInstance = new ???Index();
+
+ // Return the prepared instance
+ return $indexInstance;
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A general index class
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2012 Core Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.org
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+class BaseIndex extends BaseFrameworkSystem {
+ /**
+ * Protected constructor
+ *
+ * @param $className Name of the class
+ * @return void
+ */
+ protected function __construct ($className) {
+ // Call parent constructor
+ parent::__construct($className);
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A FileStack index class
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2012 Core Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.org
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+class FileStackIndex extends BaseIndex implements IndexableStack {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this Index class and prepares it for usage
+ *
+ * @param $fileName Name of the file stack to create an index file for
+ * @return $indexInstance An instance of this Index class
+ */
+ public final static function createFileStackIndex ($fileName) {
+ // Get a new instance
+ $indexInstance = new FileStackIndex();
+
+ // Return the prepared instance
+ return $indexInstance;
+ }
+}
+
+// [EOF]
+?>
*/
private $header = array();
+ /**
+ * Seek positions for gaps ("fragmentation")
+ */
+ private $gaps = array();
+
+ /**
+ * Seek positions for damaged entries (e.g. mismatching hash sum, ...)
+ */
+ private $damagedEntries = array();
+
/**
* Protected constructor
*
self::LENGTH_POSITION +
strlen(self::SEPARATOR_HEADER_ENTRIES)
);
+
+ // Init counters and gaps array
+ $this->initCountersGapsArray();
+ }
+
+ /**
+ * Initializes counter for valid entries, arrays for damaged entries and
+ * an array for gap seek positions. If you call this method on your own,
+ * please re-analyze the file structure. So you are better to call
+ * analyzeStackFile() instead of this method.
+ *
+ * @return void
+ */
+ private function initCountersGapsArray () {
+ // Init counter and seek position
+ $this->setCounter(0);
+ $this->setSeekPosition(0);
+
+ // Init arrays
+ $this->gaps = array();
+ $this->damagedEntries = array();
}
/**
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d:] EXIT!', __METHOD__, __LINE__));
}
+ /**
+ * Analyzes entries in stack file. This will count all found (and valid)
+ * entries, mark invalid as damaged and count gaps ("fragmentation"). If
+ * only gaps are found, the file is considered as "virgin" (no entries).
+ *
+ * @return void
+ */
+ private function analyzeStackFile () {
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d:] CALLED!', __METHOD__, __LINE__));
+
+ // Make sure the file is initialized
+ assert($this->isFileInitialized());
+
+ // Init counters and gaps array
+ $this->initCountersGapsArray();
+
+ // Output message (as this may take some time)
+ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d:] Analyzing file structure ... (this may take some time)', __METHOD__, __LINE__));
+
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d:] EXIT!', __METHOD__, __LINE__));
+ }
+
/**
* Initializes this file-based stack.
*
* @return void
*/
protected function initFileStack ($fileName) {
- // Get a file i/o pointer instance
+ // Get a file i/o pointer instance for stack file
$pointerInstance = ObjectFactory::createObjectByConfiguredName('file_raw_input_output_class', array($fileName));
// Get iterator instance
// Load the file header
$this->readFileHeader();
+
+ // Count all entries in file
+ $this->analyzeStackFile();
+
+ /*
+ * Get stack index instance. This can be used for faster
+ * "defragmentation" and startup.
+ */
+ $indexInstance = FileStackIndexFactory::createFileStackIndex($fileName);
+
+ // And set it here
+ $this->setIndexInstance($indexInstance);
}
/**
* @return $count Size of stack (array count)
*/
public function getStackCount ($stackerName) {
- // Now, count the array of entries
- $this->partialStub('stackerName=' . $stackerName);
- $count = 0;
-
- // Return result
- return $count;
+ // Now, simply return the found count value, this must be up-to-date then!
+ return $this->getCounter();
}
}
// CFG: FILE-STACK-PRE-ALLOCATE-COUNT
$cfg->setConfigEntry('file_stack_pre_allocate_count', 10000);
+// CFG: FILE-STACK-INDEX-CLASS
+$cfg->setConfigEntry('file_stack_index_class', 'FileStackIndex');
+
// [EOF]
?>