[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 10/15] Eliminate the trie->parent field
From: |
Nick Cleaton |
Subject: |
[PATCH 10/15] Eliminate the trie->parent field |
Date: |
Sat, 2 Oct 2010 07:07:44 +0100 |
The last remaining use of trie->parent occurs in the maxshift prep
pass; it can be eliminated by applying the maxshift correction to the
children of the current node rather than to the current node itself.
---
src/kwset.c | 27 ++++++++++++++-------------
1 files changed, 14 insertions(+), 13 deletions(-)
diff --git a/src/kwset.c b/src/kwset.c
index 1a899e3..c30e951 100644
--- a/src/kwset.c
+++ b/src/kwset.c
@@ -73,7 +73,6 @@ struct trie
unsigned char is_lastkid; /* True for the last of a group of siblings. */
unsigned int accepting; /* Word index of accepted word, or zero. */
struct trie *links; /* Tree of edges leaving this node. */
- struct trie *parent; /* Parent of this node. */
struct trie *next; /* List of all trie nodes in level order. */
int shift; /* Shift function for search failures. */
int maxshift; /* Max shift of self and descendents. */
@@ -350,7 +349,6 @@ install_suffix (kwset_t kws, struct cpsort_md *md, char
const *text,
{
link = allocate_and_plumb_trie_node (kwset, index, ++trie_depth, trie);
link->accepting = 0;
- link->parent = trie;
link->next = NULL;
link->lf.fail = NULL;
link->rd.depth = trie_depth;
@@ -388,7 +386,6 @@ build_trie_from_sorted_keywords (struct kwset *kwset)
kwset->trie = kwset->next_free_node++;
kwset->trie->accepting = 0;
kwset->trie->links = NULL;
- kwset->trie->parent = NULL;
kwset->trie->next = NULL;
kwset->trie->lf.fail = NULL;
kwset->trie->rd.depth = 0;
@@ -573,18 +570,22 @@ kwsprep (kwset_t kws)
and llink fields. */
for (curr = kwset->trie; curr; curr = curr->next)
{
- if (curr->parent && curr->maxshift > curr->parent->maxshift)
- curr->maxshift = curr->parent->maxshift;
- if (curr->shift > curr->maxshift)
- curr->shift = curr->maxshift;
- if (curr->links)
+ if (!(child = curr->links))
+ continue;
+
+ do
{
- struct trie *links = curr->links;
- struct trie *links_end = links;
- while (!links_end++->is_lastkid)
- ;
- plumb_siblings (&links, links_end - links);
+ if (curr->maxshift < child->maxshift)
+ child->maxshift = curr->maxshift;
+ if (child->maxshift < child->shift)
+ child->shift = child->maxshift;
}
+ while (!child++->is_lastkid);
+
+ {
+ struct trie *links = curr->links;
+ plumb_siblings (&links, child - links);
+ }
}
/* Create a vector, indexed by character code, of the outgoing links
--
1.5.6.3
- Proof of concept: kwset running 3 times smaller, Nick Cleaton, 2010/10/02
- [PATCH 01/15] Merge trie and tree into a single struct, Nick Cleaton, 2010/10/02
- [PATCH 02/15] Sort the keywords before building the trie, Nick Cleaton, 2010/10/02
- [PATCH 03/15] Lay out the trie more systematically, Nick Cleaton, 2010/10/02
- [PATCH 04/15] Lay out the trees more systematically, Nick Cleaton, 2010/10/02
- [PATCH 05/15] Avoid using llink and rlink during prep, Nick Cleaton, 2010/10/02
- [PATCH 06/15] Defer llink/rlink plumbing to the end of prep, Nick Cleaton, 2010/10/02
- [PATCH 07/15] Share storage between llink and fail, Nick Cleaton, 2010/10/02
- [PATCH 08/15] Avoid using trie->depth during matching, Nick Cleaton, 2010/10/02
- [PATCH 09/15] Share storage between rlink and depth, Nick Cleaton, 2010/10/02
- [PATCH 10/15] Eliminate the trie->parent field,
Nick Cleaton <=
- [PATCH 11/15] Eliminate the trie->next field, Nick Cleaton, 2010/10/02
- [PATCH 12/15] Eliminate the trie->maxshift field, Nick Cleaton, 2010/10/02
- [PATCH 13/15] Reduce trie->accepting to a flag, Nick Cleaton, 2010/10/02
- [PATCH 14/15] Merge flags into a trie->flags field, Nick Cleaton, 2010/10/02
- [PATCH 15/15] Make trie->shift an unsigned short, Nick Cleaton, 2010/10/02
- Re: Proof of concept: kwset running 3 times smaller, Nick Cleaton, 2010/10/30