summaryrefslogtreecommitdiffstats
path: root/generic
diff options
context:
space:
mode:
authorsebres <sebres@users.sourceforge.net>2017-05-11 15:07:41 (GMT)
committersebres <sebres@users.sourceforge.net>2017-05-11 15:07:41 (GMT)
commit1431cc558785ae702e11c2aba5a9212dd79d4d3c (patch)
tree7ab39c0fcf36a66c5b3e2df1e253e03740cfc88d /generic
parent95b07543288c057479a4d167887b372c00707dc0 (diff)
downloadtcl-1431cc558785ae702e11c2aba5a9212dd79d4d3c.zip
tcl-1431cc558785ae702e11c2aba5a9212dd79d4d3c.tar.gz
tcl-1431cc558785ae702e11c2aba5a9212dd79d4d3c.tar.bz2
[clock] tclStrIdxTree extended with possibility to hold client data; also changed in clock - indices starts with 1 instead of 0, and 0(NULL) instead of -1 used as sign of ambiguous keys.
Diffstat (limited to 'generic')
-rw-r--r--generic/tclClockFmt.c14
-rw-r--r--generic/tclStrIdxTree.c59
-rw-r--r--generic/tclStrIdxTree.h8
3 files changed, 45 insertions, 36 deletions
diff --git a/generic/tclClockFmt.c b/generic/tclClockFmt.c
index 18b82fa..70b3ad7 100644
--- a/generic/tclClockFmt.c
+++ b/generic/tclClockFmt.c
@@ -1174,7 +1174,7 @@ ClockMCGetListIdxTree(
goto done;
};
- if (TclStrIdxTreeBuildFromList(idxTree, lstc, lstv) != TCL_OK) {
+ if (TclStrIdxTreeBuildFromList(idxTree, lstc, lstv, NULL) != TCL_OK) {
goto done;
}
@@ -1249,7 +1249,7 @@ ClockMCGetMultiListIdxTree(
goto done;
};
- if (TclStrIdxTreeBuildFromList(idxTree, lstc, lstv) != TCL_OK) {
+ if (TclStrIdxTreeBuildFromList(idxTree, lstc, lstv, NULL) != TCL_OK) {
goto done;
}
mcKeys++;
@@ -1301,12 +1301,12 @@ ClockStrIdxTreeSearch(ClockFmtScnCmdArgs *opts,
/* not found */
return TCL_RETURN;
}
- if (foundItem->value == -1) {
+ if (!foundItem->value) {
/* ambigous */
return TCL_RETURN;
}
- *val = foundItem->value;
+ *val = PTR2INT(foundItem->value);
/* shift input pointer */
yyInput = f;
@@ -1406,7 +1406,7 @@ ClockScnToken_Month_Proc(ClockFmtScnCmdArgs *opts,
return ret;
}
- yyMonth = val + 1;
+ yyMonth = val;
return TCL_OK;
}
@@ -1445,6 +1445,7 @@ ClockScnToken_DayOfWeek_Proc(ClockFmtScnCmdArgs *opts,
if (ret != TCL_OK) {
return ret;
}
+ --val;
}
if (val != -1) {
@@ -1476,6 +1477,7 @@ ClockScnToken_DayOfWeek_Proc(ClockFmtScnCmdArgs *opts,
if (ret != TCL_OK) {
return ret;
}
+ --val;
if (val == 0) {
val = 7;
@@ -1578,7 +1580,7 @@ ClockScnToken_LocaleListMatcher_Proc(ClockFmtScnCmdArgs *opts,
}
if (tok->map->offs > 0) {
- *(int *)(((char *)info) + tok->map->offs) = val;
+ *(int *)(((char *)info) + tok->map->offs) = --val;
}
return TCL_OK;
diff --git a/generic/tclStrIdxTree.c b/generic/tclStrIdxTree.c
index d9b5da0..291e481 100644
--- a/generic/tclStrIdxTree.c
+++ b/generic/tclStrIdxTree.c
@@ -24,26 +24,28 @@
*
* Index-Tree:
*
- * j -1 * ...
- * anuar 0 *
- * u -1 * a -1
- * ni 5 * pril 3
- * li 6 * ugust 7
- * n -1 * gt 7
- * r 0 * s 8
- * i 5 * eptember 8
- * li 6 * pt 8
- * f 1 * oktober 9
- * ebruar 1 * n 10
- * br 1 * ovember 10
- * m -1 * vb 10
- * a -1 * d 11
- * erz 2 * ezember 11
- * i 4 * zb 11
- * rz 2 *
+ * j 0 * ...
+ * anuar 1 *
+ * u 0 * a 0
+ * ni 6 * pril 4
+ * li 7 * ugust 8
+ * n 0 * gt 8
+ * r 1 * s 9
+ * i 6 * eptember 9
+ * li 7 * pt 9
+ * f 2 * oktober 10
+ * ebruar 2 * n 11
+ * br 2 * ovember 11
+ * m 0 * vb 11
+ * a 0 * d 12
+ * erz 3 * ezember 12
+ * i 5 * zb 12
+ * rz 3 *
* ...
*
- * Thereby value -1 shows pure group items (corresponding ambigous matches).
+ * Thereby value 0 shows pure group items (corresponding ambigous matches).
+ * But the group may have a value if it contains only same values
+ * (see for example group "f" above).
*
* StrIdxTree's are very fast, so:
* build of above-mentioned tree takes about 10 microseconds.
@@ -109,7 +111,7 @@ TclStrIdxTreeSearch(
if (offs >= item->length && item->childTree.firstPtr) {
/* save previuosly found item (if not ambigous) for
* possible fallback (few greedy match) */
- if (item->value != -1) {
+ if (item->value != NULL) {
prevf = f;
prevItem = item;
prevParent = parent;
@@ -206,7 +208,9 @@ TclStrIdxTreeAppend(
* TclStrIdxTreeBuildFromList --
*
* Build or extend string indexed tree from tcl list.
- *
+ * If the values not given the values of built list are indices starts with 1.
+ * Value of 0 is thereby reserved to the ambigous values.
+ *
* Important: by multiple lists, optimal tree can be created only if list with
* larger strings used firstly.
*
@@ -223,10 +227,12 @@ MODULE_SCOPE int
TclStrIdxTreeBuildFromList(
TclStrIdxTree *idxTree,
int lstc,
- Tcl_Obj **lstv)
+ Tcl_Obj **lstv,
+ ClientData *values)
{
Tcl_Obj **lwrv;
int i, ret = TCL_ERROR;
+ ClientData val;
const char *s, *e, *f;
TclStrIdx *item;
@@ -250,8 +256,9 @@ TclStrIdxTreeBuildFromList(
TclStrIdxTree *foundParent = idxTree;
e = s = TclGetString(lwrv[i]);
e += lwrv[i]->length;
+ val = values ? values[i] : INT2PTR(i+1);
- /* ignore empty values (impossible to index it) */
+ /* ignore empty keys (impossible to index it) */
if (lwrv[i]->length == 0) continue;
item = NULL;
@@ -267,7 +274,7 @@ TclStrIdxTreeBuildFromList(
}
/* if shortest key was found with the same value,
* just replace its current key with longest key */
- if ( foundItem->value == i
+ if ( foundItem->value == val
&& foundItem->length < lwrv[i]->length
&& foundItem->childTree.firstPtr == NULL
) {
@@ -286,7 +293,7 @@ TclStrIdxTreeBuildFromList(
Tcl_InitObjRef(item->key, foundItem->key);
item->length = f - s;
/* set value or mark as ambigous if not the same value of both */
- item->value = (foundItem->value == i) ? i : -1;
+ item->value = (foundItem->value == val) ? val : NULL;
/* insert group item between foundParent and foundItem */
TclStrIdxTreeInsertBranch(foundParent, item, foundItem);
foundParent = &item->childTree;
@@ -304,7 +311,7 @@ TclStrIdxTreeBuildFromList(
item->childTree.lastPtr = item->childTree.firstPtr = NULL;
Tcl_InitObjRef(item->key, lwrv[i]);
item->length = lwrv[i]->length;
- item->value = i;
+ item->value = val;
TclStrIdxTreeAppend(foundParent, item);
};
@@ -496,7 +503,7 @@ TclStrIdxTreeTestObjCmd(
&lstc, &lstv) != TCL_OK) {
return TCL_ERROR;
};
- TclStrIdxTreeBuildFromList(&idxTree, lstc, lstv);
+ TclStrIdxTreeBuildFromList(&idxTree, lstc, lstv, NULL);
}
if (optionIndex == O_PUTS_INDEX) {
TclStrIdxTreePrint(interp, idxTree.firstPtr, 0);
diff --git a/generic/tclStrIdxTree.h b/generic/tclStrIdxTree.h
index 305053c..9f26907 100644
--- a/generic/tclStrIdxTree.h
+++ b/generic/tclStrIdxTree.h
@@ -27,9 +27,9 @@ typedef struct TclStrIdx {
struct TclStrIdxTree childTree;
struct TclStrIdx *nextPtr;
struct TclStrIdx *prevPtr;
- Tcl_Obj *key;
- int length;
- int value;
+ Tcl_Obj *key;
+ int length;
+ ClientData value;
} TclStrIdx;
@@ -152,7 +152,7 @@ MODULE_SCOPE const char*
const char *start, const char *end);
MODULE_SCOPE int TclStrIdxTreeBuildFromList(TclStrIdxTree *idxTree,
- int lstc, Tcl_Obj **lstv);
+ int lstc, Tcl_Obj **lstv, ClientData *values);
MODULE_SCOPE Tcl_Obj*
TclStrIdxTreeNewObj();