@kbw,
I checked my code for RbaseX. I forgot to code the exception for the case that there is a \ff that is not followed by a \ff or a \00. I'll have to add a test in my package for that case.
In R I implemented the encode function in the following way:
1 2 3 4 5 6 7 8 9 10 11 12
|
add_FF <- function(cache_in) {
FF <- which(255 == cache_in)
Z <- which(0 == cache_in)
addFF <- c(FF, Z)
if (length(addFF) > 0) {
val <- c(cache_in, rep(as.raw(255), length(addFF)))
id <- c(seq_along(cache_in), addFF-0.5)
val <- val[order(id)]
return(val)
} else
return(cache_in)
}
| |
cache_in <- "He\FFll\00o"
Line 2 returns an array with indices of occurence of \FF {3}. Line 3 returns the same for \00 {6).
addFF = {3, 6}
val = {H, e, FF, l, l, 00, 0, FF, FF}
id = {1, 2, 3, 4, 5, 6, 7, 2.5, 5.5}
Order val based on value of id
val = {H e FF FF l l FF 00 o)
To my knowledge in R this is the most efficient way to insert values into an array.
I'm just curious to know if C++ has a similar function for inserting values into an array?
PS,
What's the use of the check in line 29? At that point 'end' has value 0 which is interprated as false so the next line will never be executed?