summaryrefslogtreecommitdiff
path: root/decoder/static_utoa.h
diff options
context:
space:
mode:
authorgraehl@gmail.com <graehl@gmail.com@ec762483-ff6d-05da-a07a-a48fb63a330f>2010-08-02 07:57:23 +0000
committergraehl@gmail.com <graehl@gmail.com@ec762483-ff6d-05da-a07a-a48fb63a330f>2010-08-02 07:57:23 +0000
commitf9859ad4116733e145d7b8eb31c3cc9318ff7564 (patch)
tree92f6942fc7fd7066eb400bce6d2cbd2fee46c801 /decoder/static_utoa.h
parent6da285dfa7b0a1929dcec882d7e48a585e878d18 (diff)
fake tdict names for non-ids, push viterbi cost to root in hg, store as feature. type erased fsa feature via virtual interface. made lexical_cast assume C locale for speed.
git-svn-id: https://ws10smt.googlecode.com/svn/trunk@465 ec762483-ff6d-05da-a07a-a48fb63a330f
Diffstat (limited to 'decoder/static_utoa.h')
-rwxr-xr-xdecoder/static_utoa.h63
1 files changed, 63 insertions, 0 deletions
diff --git a/decoder/static_utoa.h b/decoder/static_utoa.h
new file mode 100755
index 00000000..0dbe111f
--- /dev/null
+++ b/decoder/static_utoa.h
@@ -0,0 +1,63 @@
+#ifndef STATIC_UTOA_H
+#define STATIC_UTOA_H
+
+#include "threadlocal.h"
+#include <cstring>
+
+#define DIGIT_LOOKUP_TABLE 0
+
+namespace {
+THREADLOCAL char utoa_buf[] = "01234567890123456789"; // to put end of string character at buf[20]
+const unsigned utoa_bufsize=sizeof(utoa_buf);
+const unsigned utoa_bufsizem1=utoa_bufsize-1;
+#ifdef DIGIT_LOOKUP_TABLE
+char digits[] = "0123456789";
+#endif
+}
+
+inline char digit_to_char(int d) {
+ return
+#ifdef DIGIT_LOOKUP_TABLE
+ digits[d];
+#else
+ '0'+d;
+#endif
+}
+
+
+// returns n in string [return,num); *num=0 yourself calling if you want a c_str
+inline char *utoa(char *num,unsigned n) {
+ if ( !n ) {
+ *--num='0';
+ } else {
+ unsigned rem;
+ // 3digit lookup table, divide by 1000 faster?
+ while ( n ) {
+#if 1
+ rem = n;
+ n /= 10;
+ rem -= 10*n; // maybe this is faster than mod because we are already dividing
+#else
+ rem = n%10; // would optimizer combine these together?
+ n = n/10;
+#endif
+ *--num = digit_to_char(rem);
+ }
+ }
+ return num;
+}
+
+inline char *static_utoa(unsigned n) {
+ return utoa(utoa_buf+utoa_bufsizem1,n);
+}
+
+//returns position of '\0' terminating number written starting at to
+inline char* append_utoa(char *to,unsigned n) {
+ char *s=static_utoa(n);
+ int ns=(utoa_buf+utoa_bufsize)-s;
+ std::memcpy(to,s,ns);
+ return to+ns;
+}
+
+
+#endif