X-Git-Url: http://git.madism.org/?a=blobdiff_plain;f=common%2Ftrie.c;h=9fde8e9049fb94b51f3d31f7add94ea7b218d95b;hb=8ca147e634f83b185dd4cddebde78878a69f315f;hp=ef32c962eb4aaf2a705b6fdb21d5c84a487b9415;hpb=51e206d3e16858f5cea9da95c91d5b3417d5885a;p=apps%2Fpfixtools.git diff --git a/common/trie.c b/common/trie.c index ef32c96..9fde8e9 100644 --- a/common/trie.c +++ b/common/trie.c @@ -16,17 +16,20 @@ /* products derived from this software without specific prior written */ /* permission. */ /* */ -/* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND */ -/* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE */ -/* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR */ -/* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS */ -/* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR */ -/* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF */ -/* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS */ -/* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN */ -/* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) */ -/* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF */ -/* THE POSSIBILITY OF SUCH DAMAGE. */ +/* THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS ``AS IS'' AND ANY EXPRESS */ +/* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED */ +/* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */ +/* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY */ +/* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL */ +/* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS */ +/* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) */ +/* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, */ +/* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN */ +/* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE */ +/* POSSIBILITY OF SUCH DAMAGE. */ +/* */ +/* Copyright (c) 2006-2008 the Authors */ +/* see AUTHORS and source files for details */ /******************************************************************************/ /* @@ -138,12 +141,12 @@ static inline const trie_entry_t* trie_entry_child(const trie_t *trie, const char c2 = str(trie, child)[0]; if (c2 == c) { - return child; + return child; } if (c < c2) { - end = mid; + end = mid; } else { - start = mid + 1; + start = mid + 1; } } return NULL; @@ -399,7 +402,7 @@ static inline void trie_entry_inspect(const trie_t *trie, bool show_content, if (entry->c_len == 0) { fputs("(0)", stdout); } else { - const char *c = array_ptr(trie->c, entry->c_offset); + const char *c = str(trie, entry); printf("(%d) ", entry->c_len); for (int i = 0 ; i < entry->c_len ; ++i) { if (c[i]) { @@ -411,9 +414,10 @@ static inline void trie_entry_inspect(const trie_t *trie, bool show_content, } fputs("\n", stdout); } - for (uint32_t i = entry->children_offset ; - i < entry->children_offset + entry->children_len ; ++i) { - trie_entry_inspect(trie, show_content, array_ptr(trie->entries, i), level + 1); + for (uint32_t i = 0 ; i < entry->children_len ; ++i) { + trie_entry_inspect(trie, show_content, + array_ptr(trie->entries, entry->children_offset + i), + level + 1); } if (level == 0) { printf("Average char per node: %d\n", trie->c.len / trie->entries.len);