Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #34362 > unrolled thread
| Started by | Jonas Thörnvall <jonas.thornvall@gmail.com> |
|---|---|
| First post | 2017-11-15 13:51 -0800 |
| Last post | 2017-11-22 05:04 -0800 |
| Articles | 8 — 1 participant |
Back to article view | Back to comp.lang.javascript
Insert algorithms Jonas Thörnvall <jonas.thornvall@gmail.com> - 2017-11-15 13:51 -0800
Re: Insert algorithms Jonas Thörnvall <jonas.thornvall@gmail.com> - 2017-11-15 15:05 -0800
Re: Insert algorithms Jonas Thörnvall <jonas.thornvall@gmail.com> - 2017-11-17 01:27 -0800
Re: Insert algorithms Jonas Thörnvall <jonas.thornvall@gmail.com> - 2017-11-21 17:37 -0800
Re: Insert algorithms Jonas Thörnvall <jonas.thornvall@gmail.com> - 2017-11-21 18:13 -0800
Re: Insert algorithms Jonas Thörnvall <jonas.thornvall@gmail.com> - 2017-11-22 04:41 -0800
Re: Insert algorithms Jonas Thörnvall <jonas.thornvall@gmail.com> - 2017-11-22 04:58 -0800
Re: Insert algorithms Jonas Thörnvall <jonas.thornvall@gmail.com> - 2017-11-22 05:04 -0800
| From | Jonas Thörnvall <jonas.thornvall@gmail.com> |
|---|---|
| Date | 2017-11-15 13:51 -0800 |
| Subject | Insert algorithms |
| Message-ID | <237f2e57-6614-4261-933f-d2fa22998343@googlegroups.com> |
Is it like wrong having default values start and stop predefined in an insert algorithm, i mean first item and last isn't inserting so it create specialcases if you not hardcode the interval? It seem like a nobrainer to set the insert interval borders hardcoded, but i am not sure it is correct.
[toc] | [next] | [standalone]
| From | Jonas Thörnvall <jonas.thornvall@gmail.com> |
|---|---|
| Date | 2017-11-15 15:05 -0800 |
| Message-ID | <e08f58ff-19ca-4b8b-be72-dada6e4e7f62@googlegroups.com> |
| In reply to | #34362 |
Den onsdag 15 november 2017 kl. 22:51:46 UTC+1 skrev Jonas Thörnvall: > Is it like wrong having default values start and stop predefined in an insert algorithm, i mean first item and last isn't inserting so it create specialcases if you not hardcode the interval? > > > It seem like a nobrainer to set the insert interval borders hardcoded, but i am not sure it is correct. The structure seem ok now, just need to get rid of the paragraphs and maybe try to make a little compression, and set index on occurences. http://anybase.co.nf/insert/chessbook.html
[toc] | [prev] | [next] | [standalone]
| From | Jonas Thörnvall <jonas.thornvall@gmail.com> |
|---|---|
| Date | 2017-11-17 01:27 -0800 |
| Message-ID | <84ce0b45-9253-4b1d-878b-3ba8ce4b0e08@googlegroups.com> |
| In reply to | #34364 |
Den torsdag 16 november 2017 kl. 00:05:52 UTC+1 skrev Jonas Thörnvall: > Den onsdag 15 november 2017 kl. 22:51:46 UTC+1 skrev Jonas Thörnvall: > > Is it like wrong having default values start and stop predefined in an insert algorithm, i mean first item and last isn't inserting so it create specialcases if you not hardcode the interval? > > > > > > It seem like a nobrainer to set the insert interval borders hardcoded, but i am not sure it is correct. > > The structure seem ok now, just need to get rid of the paragraphs and maybe try to make a little compression, and set index on occurences. > http://anybase.co.nf/insert/chessbook.html At some point i will try to get away from the sequential search, doing something smarter. In fact one can question if the string should not be a searchable node tree to begin with. But a node tree that is aware of its hierarchy levels.
[toc] | [prev] | [next] | [standalone]
| From | Jonas Thörnvall <jonas.thornvall@gmail.com> |
|---|---|
| Date | 2017-11-21 17:37 -0800 |
| Message-ID | <40a76c60-78c0-4fbc-88ba-a9de176db342@googlegroups.com> |
| In reply to | #34367 |
Den fredag 17 november 2017 kl. 10:27:27 UTC+1 skrev Jonas Thörnvall:
> Den torsdag 16 november 2017 kl. 00:05:52 UTC+1 skrev Jonas Thörnvall:
> > Den onsdag 15 november 2017 kl. 22:51:46 UTC+1 skrev Jonas Thörnvall:
> > > Is it like wrong having default values start and stop predefined in an insert algorithm, i mean first item and last isn't inserting so it create specialcases if you not hardcode the interval?
> > >
> > >
> > > It seem like a nobrainer to set the insert interval borders hardcoded, but i am not sure it is correct.
> >
> > The structure seem ok now, just need to get rid of the paragraphs and maybe try to make a little compression, and set index on occurences.
> > http://anybase.co.nf/insert/chessbook.html
>
> At some point i will try to get away from the sequential search, doing something smarter. In fact one can question if the string should not be a searchable node tree to begin with.
>
> But a node tree that is aware of its hierarchy levels.
Had some time to remove the paragraphs and replace with numbers tonight.
I think it is ok.
http://anybase.co.nf/insertTWO/chessbook.html
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Cache-Control" content="no-store" />
<meta http-Equiv="content-type" content="text/html; charset=UTF-8">
<link REL="StyleSheet" TYPE="text/css" HREF="drop.css">
<script type="text/javascript" src="loadsave.js"></script>
<script type="text/javascript" src="CSS.js"></script>
</head>
<script>
function createStruct() {
newword=true;
beeninside=false;
inserted = false;
endstruct = "*";
separator = " ";
subseparator = "";
newString= "";
stringPrevMem = "";
stringMem = "";
posStructString="";
//Get values to read in
startval="a*1";
endval="zzz*3";
encodedString = document.getElementById("encodedText").value;
encodedString=startval+encodedString+endval;
mystr = document.getElementById("inputTextToSave").value;
//Split string into words to read in
strArr = mystr.split(separator);
//Search words
for (var x = 0; x < strArr.length; x++) {
newString=strArr[x];
stringInserted=false;
searchItem(newString);
}
printArray();
}
function searchItem(newString) {
stringPrevMem = "";stringMem = "";z=0;
while (z < encodedString.length && stringInserted==false) {
if (encodedString.charAt(z) == "*") {
//FOUND WHOLE WORD
newword=true; beeninside=false;
// alert("WORD FOUND, STRINGMEM="+stringMem);
} else if (!isNaN(parseInt(encodedString.charAt(z)))) {
// alert("FOUND FORK AT CHARACTER NUMBER -> "+encodedString.charAt(z)+" z="+z);
stringMem = stringMem.slice(0,-encodedString.charAt(z));
} else {
stringMem += encodedString.charAt(z);
newSubString=newString.substring(0,stringMem.length);
// alert("Kodad sträng i minne "+stringMem+" Ny sträng i minne "+newSubString);
if (newSubString==stringMem) {
// alert("Strings equal size");
oldStructLength=z;
document.getElementById("debug").value+="Old position="+oldStructLength+" EQUAL Newstring="+newSubString+" Stringmem="+stringMem+" Prevstringmem="+stringPrevMem+"\n";
}
else if (newSubString>stringMem && newword==true && beeninside==false) {
// alert("Newsubstring bigger");
oldStructLength=z;
newword=false;beeninside=true;
stringPrevMem = stringMem;
}
else if (newSubString<stringMem) {
// alert("Newsubstring smaller *INSERT*");
oldStructLength=z;
checkWhatTOInsert();
}
}
z++;
}
}
function checkWhatTOInsert(){
putString="";
insertString = newString.substring(newSubString.length-1, newString.length);
insertChar = insertString.split('');
for (var m=0;m<insertChar.length;m++){
putString+=insertChar[m];
}
putString+="*";
putString+=insertChar.length;
encodedString=insertSubstring(encodedString,oldStructLength,putString);
document.getElementById("encodedText").value=encodedString;
stringInserted=true;
//alert ("NEW ENCODEDSTRING "+encodedString);
}
function insertSubstring(str, index, value) {
return str.substr(0, index) + value + str.substr(index);
}
function printArray() {
document.getElementById("decodedText").value="";
encodedString = document.getElementById("encodedText").value;
stringMem="";
for (var z = 0; z < encodedString.length; z++) {
if (!isNaN(parseInt(encodedString.charAt(z)))) {
stringMem = stringMem.slice(0,-encodedString.charAt(z));
} else if (encodedString.charAt(z) == "*") {
document.getElementById("decodedText").value+=stringMem+"\n";
} else {
stringMem += encodedString.charAt(z);
}
}
}
</script>
<body onload="printArray();">
<div class="dropdown">
<button onClick="MA()" class="dropbtn"><B>___File___</button>
<div id="MA" class="dropdown-content">
<button onclick="newFile()" class="button"><B>New File</B></button>
<br>
<label class="custom-file-upload">
<input type="file"/ id="fileToLoad" onchange="loadFileAsText()"><B> Load File</B>
</label>
<br>
<button onclick="saveTextAsFile()" class="button"><B> Save File</B></button><input id="inputFileNameToSaveAs" value="newfile.txt"></input>
</div>
</div>
<br>
<Font size="4">DEBUG</Font><br>
<textarea id="debug" cols="80" rows="3"></textarea><br>
<br>
<button onclick="createStruct()">INSERT BUTTON!</button>
<br>
<Font size="4">INSERT IN STRUCTURE</Font><br>
<textarea id="inputTextToSave" cols="80" rows="12">stop come lose fine hope happy lovely me jumping tree basket ball banana bar bad bank</textarea><br>
<br>
<Font size="4">STRUCTURE</Font><br>
<textarea id="encodedText" cols="80" rows="12">ball*2nana*4t*2un*1tt*4</textarea><br>
<br>
<Font size="4">CONTENT READ OUT FROM STRUCTURE</Font><br>
<textarea id="decodedText" cols="80" rows="12"></textarea><br>
</body>
</html>
[toc] | [prev] | [next] | [standalone]
| From | Jonas Thörnvall <jonas.thornvall@gmail.com> |
|---|---|
| Date | 2017-11-21 18:13 -0800 |
| Message-ID | <bf5be503-519d-4554-83ea-0b8a2e698635@googlegroups.com> |
| In reply to | #34378 |
Den onsdag 22 november 2017 kl. 02:37:45 UTC+1 skrev Jonas Thörnvall:
> Den fredag 17 november 2017 kl. 10:27:27 UTC+1 skrev Jonas Thörnvall:
> > Den torsdag 16 november 2017 kl. 00:05:52 UTC+1 skrev Jonas Thörnvall:
> > > Den onsdag 15 november 2017 kl. 22:51:46 UTC+1 skrev Jonas Thörnvall:
> > > > Is it like wrong having default values start and stop predefined in an insert algorithm, i mean first item and last isn't inserting so it create specialcases if you not hardcode the interval?
> > > >
> > > >
> > > > It seem like a nobrainer to set the insert interval borders hardcoded, but i am not sure it is correct.
> > >
> > > The structure seem ok now, just need to get rid of the paragraphs and maybe try to make a little compression, and set index on occurences.
> > > http://anybase.co.nf/insert/chessbook.html
> >
> > At some point i will try to get away from the sequential search, doing something smarter. In fact one can question if the string should not be a searchable node tree to begin with.
> >
> > But a node tree that is aware of its hierarchy levels.
>
> Had some time to remove the paragraphs and replace with numbers tonight.
> I think it is ok.
>
> http://anybase.co.nf/insertTWO/chessbook.html
>
> <!DOCTYPE html>
> <html>
> <head>
> <meta http-equiv="Cache-Control" content="no-store" />
> <meta http-Equiv="content-type" content="text/html; charset=UTF-8">
> <link REL="StyleSheet" TYPE="text/css" HREF="drop.css">
> <script type="text/javascript" src="loadsave.js"></script>
> <script type="text/javascript" src="CSS.js"></script>
> </head>
> <script>
>
> function createStruct() {
> newword=true;
> beeninside=false;
> inserted = false;
> endstruct = "*";
> separator = " ";
> subseparator = "";
> newString= "";
> stringPrevMem = "";
> stringMem = "";
> posStructString="";
> //Get values to read in
> startval="a*1";
> endval="zzz*3";
> encodedString = document.getElementById("encodedText").value;
> encodedString=startval+encodedString+endval;
> mystr = document.getElementById("inputTextToSave").value;
> //Split string into words to read in
> strArr = mystr.split(separator);
> //Search words
> for (var x = 0; x < strArr.length; x++) {
> newString=strArr[x];
> stringInserted=false;
> searchItem(newString);
> }
> printArray();
> }
>
> function searchItem(newString) {
> stringPrevMem = "";stringMem = "";z=0;
> while (z < encodedString.length && stringInserted==false) {
> if (encodedString.charAt(z) == "*") {
> //FOUND WHOLE WORD
> newword=true; beeninside=false;
> // alert("WORD FOUND, STRINGMEM="+stringMem);
> } else if (!isNaN(parseInt(encodedString.charAt(z)))) {
> // alert("FOUND FORK AT CHARACTER NUMBER -> "+encodedString.charAt(z)+" z="+z);
> stringMem = stringMem.slice(0,-encodedString.charAt(z));
> } else {
> stringMem += encodedString.charAt(z);
> newSubString=newString.substring(0,stringMem.length);
> // alert("Kodad sträng i minne "+stringMem+" Ny sträng i minne "+newSubString);
> if (newSubString==stringMem) {
> // alert("Strings equal size");
> oldStructLength=z;
> document.getElementById("debug").value+="Old position="+oldStructLength+" EQUAL Newstring="+newSubString+" Stringmem="+stringMem+" Prevstringmem="+stringPrevMem+"\n";
> }
> else if (newSubString>stringMem && newword==true && beeninside==false) {
> // alert("Newsubstring bigger");
> oldStructLength=z;
> newword=false;beeninside=true;
> stringPrevMem = stringMem;
> }
> else if (newSubString<stringMem) {
> // alert("Newsubstring smaller *INSERT*");
> oldStructLength=z;
> checkWhatTOInsert();
> }
> }
> z++;
> }
> }
>
> function checkWhatTOInsert(){
> putString="";
> insertString = newString.substring(newSubString.length-1, newString.length);
> insertChar = insertString.split('');
> for (var m=0;m<insertChar.length;m++){
> putString+=insertChar[m];
> }
> putString+="*";
> putString+=insertChar.length;
> encodedString=insertSubstring(encodedString,oldStructLength,putString);
> document.getElementById("encodedText").value=encodedString;
> stringInserted=true;
> //alert ("NEW ENCODEDSTRING "+encodedString);
> }
>
> function insertSubstring(str, index, value) {
> return str.substr(0, index) + value + str.substr(index);
> }
>
> function printArray() {
> document.getElementById("decodedText").value="";
> encodedString = document.getElementById("encodedText").value;
> stringMem="";
> for (var z = 0; z < encodedString.length; z++) {
> if (!isNaN(parseInt(encodedString.charAt(z)))) {
> stringMem = stringMem.slice(0,-encodedString.charAt(z));
> } else if (encodedString.charAt(z) == "*") {
> document.getElementById("decodedText").value+=stringMem+"\n";
> } else {
> stringMem += encodedString.charAt(z);
> }
> }
> }
>
> </script>
> <body onload="printArray();">
> <div class="dropdown">
> <button onClick="MA()" class="dropbtn"><B>___File___</button>
> <div id="MA" class="dropdown-content">
> <button onclick="newFile()" class="button"><B>New File</B></button>
> <br>
> <label class="custom-file-upload">
> <input type="file"/ id="fileToLoad" onchange="loadFileAsText()"><B> Load File</B>
> </label>
> <br>
> <button onclick="saveTextAsFile()" class="button"><B> Save File</B></button><input id="inputFileNameToSaveAs" value="newfile.txt"></input>
> </div>
> </div>
> <br>
> <Font size="4">DEBUG</Font><br>
> <textarea id="debug" cols="80" rows="3"></textarea><br>
> <br>
> <button onclick="createStruct()">INSERT BUTTON!</button>
> <br>
> <Font size="4">INSERT IN STRUCTURE</Font><br>
> <textarea id="inputTextToSave" cols="80" rows="12">stop come lose fine hope happy lovely me jumping tree basket ball banana bar bad bank</textarea><br>
> <br>
> <Font size="4">STRUCTURE</Font><br>
> <textarea id="encodedText" cols="80" rows="12">ball*2nana*4t*2un*1tt*4</textarea><br>
> <br>
> <Font size="4">CONTENT READ OUT FROM STRUCTURE</Font><br>
> <textarea id="decodedText" cols="80" rows="12"></textarea><br>
> </body>
> </html>
There is a bug it does not fork correct...
[toc] | [prev] | [next] | [standalone]
| From | Jonas Thörnvall <jonas.thornvall@gmail.com> |
|---|---|
| Date | 2017-11-22 04:41 -0800 |
| Message-ID | <57d973df-c986-49eb-8632-e29e2666d821@googlegroups.com> |
| In reply to | #34380 |
Den onsdag 22 november 2017 kl. 03:13:29 UTC+1 skrev Jonas Thörnvall:
> Den onsdag 22 november 2017 kl. 02:37:45 UTC+1 skrev Jonas Thörnvall:
> > Den fredag 17 november 2017 kl. 10:27:27 UTC+1 skrev Jonas Thörnvall:
> > > Den torsdag 16 november 2017 kl. 00:05:52 UTC+1 skrev Jonas Thörnvall:
> > > > Den onsdag 15 november 2017 kl. 22:51:46 UTC+1 skrev Jonas Thörnvall:
> > > > > Is it like wrong having default values start and stop predefined in an insert algorithm, i mean first item and last isn't inserting so it create specialcases if you not hardcode the interval?
> > > > >
> > > > >
> > > > > It seem like a nobrainer to set the insert interval borders hardcoded, but i am not sure it is correct.
> > > >
> > > > The structure seem ok now, just need to get rid of the paragraphs and maybe try to make a little compression, and set index on occurences.
> > > > http://anybase.co.nf/insert/chessbook.html
> > >
> > > At some point i will try to get away from the sequential search, doing something smarter. In fact one can question if the string should not be a searchable node tree to begin with.
> > >
> > > But a node tree that is aware of its hierarchy levels.
> >
> > Had some time to remove the paragraphs and replace with numbers tonight.
> > I think it is ok.
> >
> > http://anybase.co.nf/insertTWO/chessbook.html
> >
> > <!DOCTYPE html>
> > <html>
> > <head>
> > <meta http-equiv="Cache-Control" content="no-store" />
> > <meta http-Equiv="content-type" content="text/html; charset=UTF-8">
> > <link REL="StyleSheet" TYPE="text/css" HREF="drop.css">
> > <script type="text/javascript" src="loadsave.js"></script>
> > <script type="text/javascript" src="CSS.js"></script>
> > </head>
> > <script>
> >
> > function createStruct() {
> > newword=true;
> > beeninside=false;
> > inserted = false;
> > endstruct = "*";
> > separator = " ";
> > subseparator = "";
> > newString= "";
> > stringPrevMem = "";
> > stringMem = "";
> > posStructString="";
> > //Get values to read in
> > startval="a*1";
> > endval="zzz*3";
> > encodedString = document.getElementById("encodedText").value;
> > encodedString=startval+encodedString+endval;
> > mystr = document.getElementById("inputTextToSave").value;
> > //Split string into words to read in
> > strArr = mystr.split(separator);
> > //Search words
> > for (var x = 0; x < strArr.length; x++) {
> > newString=strArr[x];
> > stringInserted=false;
> > searchItem(newString);
> > }
> > printArray();
> > }
> >
> > function searchItem(newString) {
> > stringPrevMem = "";stringMem = "";z=0;
> > while (z < encodedString.length && stringInserted==false) {
> > if (encodedString.charAt(z) == "*") {
> > //FOUND WHOLE WORD
> > newword=true; beeninside=false;
> > // alert("WORD FOUND, STRINGMEM="+stringMem);
> > } else if (!isNaN(parseInt(encodedString.charAt(z)))) {
> > // alert("FOUND FORK AT CHARACTER NUMBER -> "+encodedString.charAt(z)+" z="+z);
> > stringMem = stringMem.slice(0,-encodedString.charAt(z));
> > } else {
> > stringMem += encodedString.charAt(z);
> > newSubString=newString.substring(0,stringMem.length);
> > // alert("Kodad sträng i minne "+stringMem+" Ny sträng i minne "+newSubString);
> > if (newSubString==stringMem) {
> > // alert("Strings equal size");
> > oldStructLength=z;
> > document.getElementById("debug").value+="Old position="+oldStructLength+" EQUAL Newstring="+newSubString+" Stringmem="+stringMem+" Prevstringmem="+stringPrevMem+"\n";
> > }
> > else if (newSubString>stringMem && newword==true && beeninside==false) {
> > // alert("Newsubstring bigger");
> > oldStructLength=z;
> > newword=false;beeninside=true;
> > stringPrevMem = stringMem;
> > }
> > else if (newSubString<stringMem) {
> > // alert("Newsubstring smaller *INSERT*");
> > oldStructLength=z;
> > checkWhatTOInsert();
> > }
> > }
> > z++;
> > }
> > }
> >
> > function checkWhatTOInsert(){
> > putString="";
> > insertString = newString.substring(newSubString.length-1, newString.length);
> > insertChar = insertString.split('');
> > for (var m=0;m<insertChar.length;m++){
> > putString+=insertChar[m];
> > }
> > putString+="*";
> > putString+=insertChar.length;
> > encodedString=insertSubstring(encodedString,oldStructLength,putString);
> > document.getElementById("encodedText").value=encodedString;
> > stringInserted=true;
> > //alert ("NEW ENCODEDSTRING "+encodedString);
> > }
> >
> > function insertSubstring(str, index, value) {
> > return str.substr(0, index) + value + str.substr(index);
> > }
> >
> > function printArray() {
> > document.getElementById("decodedText").value="";
> > encodedString = document.getElementById("encodedText").value;
> > stringMem="";
> > for (var z = 0; z < encodedString.length; z++) {
> > if (!isNaN(parseInt(encodedString.charAt(z)))) {
> > stringMem = stringMem.slice(0,-encodedString.charAt(z));
> > } else if (encodedString.charAt(z) == "*") {
> > document.getElementById("decodedText").value+=stringMem+"\n";
> > } else {
> > stringMem += encodedString.charAt(z);
> > }
> > }
> > }
> >
> > </script>
> > <body onload="printArray();">
> > <div class="dropdown">
> > <button onClick="MA()" class="dropbtn"><B>___File___</button>
> > <div id="MA" class="dropdown-content">
> > <button onclick="newFile()" class="button"><B>New File</B></button>
> > <br>
> > <label class="custom-file-upload">
> > <input type="file"/ id="fileToLoad" onchange="loadFileAsText()"><B> Load File</B>
> > </label>
> > <br>
> > <button onclick="saveTextAsFile()" class="button"><B> Save File</B></button><input id="inputFileNameToSaveAs" value="newfile.txt"></input>
> > </div>
> > </div>
> > <br>
> > <Font size="4">DEBUG</Font><br>
> > <textarea id="debug" cols="80" rows="3"></textarea><br>
> > <br>
> > <button onclick="createStruct()">INSERT BUTTON!</button>
> > <br>
> > <Font size="4">INSERT IN STRUCTURE</Font><br>
> > <textarea id="inputTextToSave" cols="80" rows="12">stop come lose fine hope happy lovely me jumping tree basket ball banana bar bad bank</textarea><br>
> > <br>
> > <Font size="4">STRUCTURE</Font><br>
> > <textarea id="encodedText" cols="80" rows="12">ball*2nana*4t*2un*1tt*4</textarea><br>
> > <br>
> > <Font size="4">CONTENT READ OUT FROM STRUCTURE</Font><br>
> > <textarea id="decodedText" cols="80" rows="12"></textarea><br>
> > </body>
> > </html>
>
> There is a bug it does not fork correct...
I just had a look at the paragraph version, it have same problem with the fork when inserting.
If anyone can see what goes wrong i am interested, my biggest fear is that it is a cascading problem in structure. I don't think it could be, but i have not thought that deep about it because i figured it would not be to start with.
Lets hope it just a case i missed...
If you have time and spot it tell me, otherwise i have to think and that is a cumbersome process.
Paragraph forking structure
http://anybase.co.nf/insert/chessbook.html
Number forking same structure "removed paragraphs"
http://anybase.co.nf/insertTWO/chessbook.html
[toc] | [prev] | [next] | [standalone]
| From | Jonas Thörnvall <jonas.thornvall@gmail.com> |
|---|---|
| Date | 2017-11-22 04:58 -0800 |
| Message-ID | <aec1153b-0aaa-41dc-8cfb-acdd12eec010@googlegroups.com> |
| In reply to | #34382 |
Den onsdag 22 november 2017 kl. 13:41:37 UTC+1 skrev Jonas Thörnvall:
> Den onsdag 22 november 2017 kl. 03:13:29 UTC+1 skrev Jonas Thörnvall:
> > Den onsdag 22 november 2017 kl. 02:37:45 UTC+1 skrev Jonas Thörnvall:
> > > Den fredag 17 november 2017 kl. 10:27:27 UTC+1 skrev Jonas Thörnvall:
> > > > Den torsdag 16 november 2017 kl. 00:05:52 UTC+1 skrev Jonas Thörnvall:
> > > > > Den onsdag 15 november 2017 kl. 22:51:46 UTC+1 skrev Jonas Thörnvall:
> > > > > > Is it like wrong having default values start and stop predefined in an insert algorithm, i mean first item and last isn't inserting so it create specialcases if you not hardcode the interval?
> > > > > >
> > > > > >
> > > > > > It seem like a nobrainer to set the insert interval borders hardcoded, but i am not sure it is correct.
> > > > >
> > > > > The structure seem ok now, just need to get rid of the paragraphs and maybe try to make a little compression, and set index on occurences.
> > > > > http://anybase.co.nf/insert/chessbook.html
> > > >
> > > > At some point i will try to get away from the sequential search, doing something smarter. In fact one can question if the string should not be a searchable node tree to begin with.
> > > >
> > > > But a node tree that is aware of its hierarchy levels.
> > >
> > > Had some time to remove the paragraphs and replace with numbers tonight.
> > > I think it is ok.
> > >
> > > http://anybase.co.nf/insertTWO/chessbook.html
> > >
> > > <!DOCTYPE html>
> > > <html>
> > > <head>
> > > <meta http-equiv="Cache-Control" content="no-store" />
> > > <meta http-Equiv="content-type" content="text/html; charset=UTF-8">
> > > <link REL="StyleSheet" TYPE="text/css" HREF="drop.css">
> > > <script type="text/javascript" src="loadsave.js"></script>
> > > <script type="text/javascript" src="CSS.js"></script>
> > > </head>
> > > <script>
> > >
> > > function createStruct() {
> > > newword=true;
> > > beeninside=false;
> > > inserted = false;
> > > endstruct = "*";
> > > separator = " ";
> > > subseparator = "";
> > > newString= "";
> > > stringPrevMem = "";
> > > stringMem = "";
> > > posStructString="";
> > > //Get values to read in
> > > startval="a*1";
> > > endval="zzz*3";
> > > encodedString = document.getElementById("encodedText").value;
> > > encodedString=startval+encodedString+endval;
> > > mystr = document.getElementById("inputTextToSave").value;
> > > //Split string into words to read in
> > > strArr = mystr.split(separator);
> > > //Search words
> > > for (var x = 0; x < strArr.length; x++) {
> > > newString=strArr[x];
> > > stringInserted=false;
> > > searchItem(newString);
> > > }
> > > printArray();
> > > }
> > >
> > > function searchItem(newString) {
> > > stringPrevMem = "";stringMem = "";z=0;
> > > while (z < encodedString.length && stringInserted==false) {
> > > if (encodedString.charAt(z) == "*") {
> > > //FOUND WHOLE WORD
> > > newword=true; beeninside=false;
> > > // alert("WORD FOUND, STRINGMEM="+stringMem);
> > > } else if (!isNaN(parseInt(encodedString.charAt(z)))) {
> > > // alert("FOUND FORK AT CHARACTER NUMBER -> "+encodedString.charAt(z)+" z="+z);
> > > stringMem = stringMem.slice(0,-encodedString.charAt(z));
> > > } else {
> > > stringMem += encodedString.charAt(z);
> > > newSubString=newString.substring(0,stringMem.length);
> > > // alert("Kodad sträng i minne "+stringMem+" Ny sträng i minne "+newSubString);
> > > if (newSubString==stringMem) {
> > > // alert("Strings equal size");
> > > oldStructLength=z;
> > > document.getElementById("debug").value+="Old position="+oldStructLength+" EQUAL Newstring="+newSubString+" Stringmem="+stringMem+" Prevstringmem="+stringPrevMem+"\n";
> > > }
> > > else if (newSubString>stringMem && newword==true && beeninside==false) {
> > > // alert("Newsubstring bigger");
> > > oldStructLength=z;
> > > newword=false;beeninside=true;
> > > stringPrevMem = stringMem;
> > > }
> > > else if (newSubString<stringMem) {
> > > // alert("Newsubstring smaller *INSERT*");
> > > oldStructLength=z;
> > > checkWhatTOInsert();
> > > }
> > > }
> > > z++;
> > > }
> > > }
> > >
> > > function checkWhatTOInsert(){
> > > putString="";
> > > insertString = newString.substring(newSubString.length-1, newString.length);
> > > insertChar = insertString.split('');
> > > for (var m=0;m<insertChar.length;m++){
> > > putString+=insertChar[m];
> > > }
> > > putString+="*";
> > > putString+=insertChar.length;
> > > encodedString=insertSubstring(encodedString,oldStructLength,putString);
> > > document.getElementById("encodedText").value=encodedString;
> > > stringInserted=true;
> > > //alert ("NEW ENCODEDSTRING "+encodedString);
> > > }
> > >
> > > function insertSubstring(str, index, value) {
> > > return str.substr(0, index) + value + str.substr(index);
> > > }
> > >
> > > function printArray() {
> > > document.getElementById("decodedText").value="";
> > > encodedString = document.getElementById("encodedText").value;
> > > stringMem="";
> > > for (var z = 0; z < encodedString.length; z++) {
> > > if (!isNaN(parseInt(encodedString.charAt(z)))) {
> > > stringMem = stringMem.slice(0,-encodedString.charAt(z));
> > > } else if (encodedString.charAt(z) == "*") {
> > > document.getElementById("decodedText").value+=stringMem+"\n";
> > > } else {
> > > stringMem += encodedString.charAt(z);
> > > }
> > > }
> > > }
> > >
> > > </script>
> > > <body onload="printArray();">
> > > <div class="dropdown">
> > > <button onClick="MA()" class="dropbtn"><B>___File___</button>
> > > <div id="MA" class="dropdown-content">
> > > <button onclick="newFile()" class="button"><B>New File</B></button>
> > > <br>
> > > <label class="custom-file-upload">
> > > <input type="file"/ id="fileToLoad" onchange="loadFileAsText()"><B> Load File</B>
> > > </label>
> > > <br>
> > > <button onclick="saveTextAsFile()" class="button"><B> Save File</B></button><input id="inputFileNameToSaveAs" value="newfile.txt"></input>
> > > </div>
> > > </div>
> > > <br>
> > > <Font size="4">DEBUG</Font><br>
> > > <textarea id="debug" cols="80" rows="3"></textarea><br>
> > > <br>
> > > <button onclick="createStruct()">INSERT BUTTON!</button>
> > > <br>
> > > <Font size="4">INSERT IN STRUCTURE</Font><br>
> > > <textarea id="inputTextToSave" cols="80" rows="12">stop come lose fine hope happy lovely me jumping tree basket ball banana bar bad bank</textarea><br>
> > > <br>
> > > <Font size="4">STRUCTURE</Font><br>
> > > <textarea id="encodedText" cols="80" rows="12">ball*2nana*4t*2un*1tt*4</textarea><br>
> > > <br>
> > > <Font size="4">CONTENT READ OUT FROM STRUCTURE</Font><br>
> > > <textarea id="decodedText" cols="80" rows="12"></textarea><br>
> > > </body>
> > > </html>
> >
> > There is a bug it does not fork correct...
>
> I just had a look at the paragraph version, it have same problem with the fork when inserting.
>
> If anyone can see what goes wrong i am interested, my biggest fear is that it is a cascading problem in structure. I don't think it could be, but i have not thought that deep about it because i figured it would not be to start with.
>
> Lets hope it just a case i missed...
> If you have time and spot it tell me, otherwise i have to think and that is a cumbersome process.
>
> Paragraph forking structure
> http://anybase.co.nf/insert/chessbook.html
>
> Number forking same structure "removed paragraphs"
> http://anybase.co.nf/insertTWO/chessbook.html
First occurence of miss forking seem to be at
B IN MEMORY [e[d*]][e[l[l*]]]
There is no need to save the "e" when forking it is in both structures.
And in the paragraph free version same problem bed is closing two when only need to save one to fork.
B IN MEMORY *2ed*2ell*
Well more debugging ahead, it seem weird it seem to fork correct in most? cases but suddenly it doesn't place the fork of branchtree correct. Probably a substring hold and compared isn't what i thought it was?
[toc] | [prev] | [next] | [standalone]
| From | Jonas Thörnvall <jonas.thornvall@gmail.com> |
|---|---|
| Date | 2017-11-22 05:04 -0800 |
| Message-ID | <937c598f-5d1f-41e8-9f76-023893cd91fa@googlegroups.com> |
| In reply to | #34383 |
Den onsdag 22 november 2017 kl. 13:58:56 UTC+1 skrev Jonas Thörnvall:
> Den onsdag 22 november 2017 kl. 13:41:37 UTC+1 skrev Jonas Thörnvall:
> > Den onsdag 22 november 2017 kl. 03:13:29 UTC+1 skrev Jonas Thörnvall:
> > > Den onsdag 22 november 2017 kl. 02:37:45 UTC+1 skrev Jonas Thörnvall:
> > > > Den fredag 17 november 2017 kl. 10:27:27 UTC+1 skrev Jonas Thörnvall:
> > > > > Den torsdag 16 november 2017 kl. 00:05:52 UTC+1 skrev Jonas Thörnvall:
> > > > > > Den onsdag 15 november 2017 kl. 22:51:46 UTC+1 skrev Jonas Thörnvall:
> > > > > > > Is it like wrong having default values start and stop predefined in an insert algorithm, i mean first item and last isn't inserting so it create specialcases if you not hardcode the interval?
> > > > > > >
> > > > > > >
> > > > > > > It seem like a nobrainer to set the insert interval borders hardcoded, but i am not sure it is correct.
> > > > > >
> > > > > > The structure seem ok now, just need to get rid of the paragraphs and maybe try to make a little compression, and set index on occurences.
> > > > > > http://anybase.co.nf/insert/chessbook.html
> > > > >
> > > > > At some point i will try to get away from the sequential search, doing something smarter. In fact one can question if the string should not be a searchable node tree to begin with.
> > > > >
> > > > > But a node tree that is aware of its hierarchy levels.
> > > >
> > > > Had some time to remove the paragraphs and replace with numbers tonight.
> > > > I think it is ok.
> > > >
> > > > http://anybase.co.nf/insertTWO/chessbook.html
> > > >
> > > > <!DOCTYPE html>
> > > > <html>
> > > > <head>
> > > > <meta http-equiv="Cache-Control" content="no-store" />
> > > > <meta http-Equiv="content-type" content="text/html; charset=UTF-8">
> > > > <link REL="StyleSheet" TYPE="text/css" HREF="drop.css">
> > > > <script type="text/javascript" src="loadsave.js"></script>
> > > > <script type="text/javascript" src="CSS.js"></script>
> > > > </head>
> > > > <script>
> > > >
> > > > function createStruct() {
> > > > newword=true;
> > > > beeninside=false;
> > > > inserted = false;
> > > > endstruct = "*";
> > > > separator = " ";
> > > > subseparator = "";
> > > > newString= "";
> > > > stringPrevMem = "";
> > > > stringMem = "";
> > > > posStructString="";
> > > > //Get values to read in
> > > > startval="a*1";
> > > > endval="zzz*3";
> > > > encodedString = document.getElementById("encodedText").value;
> > > > encodedString=startval+encodedString+endval;
> > > > mystr = document.getElementById("inputTextToSave").value;
> > > > //Split string into words to read in
> > > > strArr = mystr.split(separator);
> > > > //Search words
> > > > for (var x = 0; x < strArr.length; x++) {
> > > > newString=strArr[x];
> > > > stringInserted=false;
> > > > searchItem(newString);
> > > > }
> > > > printArray();
> > > > }
> > > >
> > > > function searchItem(newString) {
> > > > stringPrevMem = "";stringMem = "";z=0;
> > > > while (z < encodedString.length && stringInserted==false) {
> > > > if (encodedString.charAt(z) == "*") {
> > > > //FOUND WHOLE WORD
> > > > newword=true; beeninside=false;
> > > > // alert("WORD FOUND, STRINGMEM="+stringMem);
> > > > } else if (!isNaN(parseInt(encodedString.charAt(z)))) {
> > > > // alert("FOUND FORK AT CHARACTER NUMBER -> "+encodedString.charAt(z)+" z="+z);
> > > > stringMem = stringMem.slice(0,-encodedString.charAt(z));
> > > > } else {
> > > > stringMem += encodedString.charAt(z);
> > > > newSubString=newString.substring(0,stringMem.length);
> > > > // alert("Kodad sträng i minne "+stringMem+" Ny sträng i minne "+newSubString);
> > > > if (newSubString==stringMem) {
> > > > // alert("Strings equal size");
> > > > oldStructLength=z;
> > > > document.getElementById("debug").value+="Old position="+oldStructLength+" EQUAL Newstring="+newSubString+" Stringmem="+stringMem+" Prevstringmem="+stringPrevMem+"\n";
> > > > }
> > > > else if (newSubString>stringMem && newword==true && beeninside==false) {
> > > > // alert("Newsubstring bigger");
> > > > oldStructLength=z;
> > > > newword=false;beeninside=true;
> > > > stringPrevMem = stringMem;
> > > > }
> > > > else if (newSubString<stringMem) {
> > > > // alert("Newsubstring smaller *INSERT*");
> > > > oldStructLength=z;
> > > > checkWhatTOInsert();
> > > > }
> > > > }
> > > > z++;
> > > > }
> > > > }
> > > >
> > > > function checkWhatTOInsert(){
> > > > putString="";
> > > > insertString = newString.substring(newSubString.length-1, newString.length);
> > > > insertChar = insertString.split('');
> > > > for (var m=0;m<insertChar.length;m++){
> > > > putString+=insertChar[m];
> > > > }
> > > > putString+="*";
> > > > putString+=insertChar.length;
> > > > encodedString=insertSubstring(encodedString,oldStructLength,putString);
> > > > document.getElementById("encodedText").value=encodedString;
> > > > stringInserted=true;
> > > > //alert ("NEW ENCODEDSTRING "+encodedString);
> > > > }
> > > >
> > > > function insertSubstring(str, index, value) {
> > > > return str.substr(0, index) + value + str.substr(index);
> > > > }
> > > >
> > > > function printArray() {
> > > > document.getElementById("decodedText").value="";
> > > > encodedString = document.getElementById("encodedText").value;
> > > > stringMem="";
> > > > for (var z = 0; z < encodedString.length; z++) {
> > > > if (!isNaN(parseInt(encodedString.charAt(z)))) {
> > > > stringMem = stringMem.slice(0,-encodedString.charAt(z));
> > > > } else if (encodedString.charAt(z) == "*") {
> > > > document.getElementById("decodedText").value+=stringMem+"\n";
> > > > } else {
> > > > stringMem += encodedString.charAt(z);
> > > > }
> > > > }
> > > > }
> > > >
> > > > </script>
> > > > <body onload="printArray();">
> > > > <div class="dropdown">
> > > > <button onClick="MA()" class="dropbtn"><B>___File___</button>
> > > > <div id="MA" class="dropdown-content">
> > > > <button onclick="newFile()" class="button"><B>New File</B></button>
> > > > <br>
> > > > <label class="custom-file-upload">
> > > > <input type="file"/ id="fileToLoad" onchange="loadFileAsText()"><B> Load File</B>
> > > > </label>
> > > > <br>
> > > > <button onclick="saveTextAsFile()" class="button"><B> Save File</B></button><input id="inputFileNameToSaveAs" value="newfile.txt"></input>
> > > > </div>
> > > > </div>
> > > > <br>
> > > > <Font size="4">DEBUG</Font><br>
> > > > <textarea id="debug" cols="80" rows="3"></textarea><br>
> > > > <br>
> > > > <button onclick="createStruct()">INSERT BUTTON!</button>
> > > > <br>
> > > > <Font size="4">INSERT IN STRUCTURE</Font><br>
> > > > <textarea id="inputTextToSave" cols="80" rows="12">stop come lose fine hope happy lovely me jumping tree basket ball banana bar bad bank</textarea><br>
> > > > <br>
> > > > <Font size="4">STRUCTURE</Font><br>
> > > > <textarea id="encodedText" cols="80" rows="12">ball*2nana*4t*2un*1tt*4</textarea><br>
> > > > <br>
> > > > <Font size="4">CONTENT READ OUT FROM STRUCTURE</Font><br>
> > > > <textarea id="decodedText" cols="80" rows="12"></textarea><br>
> > > > </body>
> > > > </html>
> > >
> > > There is a bug it does not fork correct...
> >
> > I just had a look at the paragraph version, it have same problem with the fork when inserting.
> >
> > If anyone can see what goes wrong i am interested, my biggest fear is that it is a cascading problem in structure. I don't think it could be, but i have not thought that deep about it because i figured it would not be to start with.
> >
> > Lets hope it just a case i missed...
> > If you have time and spot it tell me, otherwise i have to think and that is a cumbersome process.
> >
> > Paragraph forking structure
> > http://anybase.co.nf/insert/chessbook.html
> >
> > Number forking same structure "removed paragraphs"
> > http://anybase.co.nf/insertTWO/chessbook.html
>
> First occurence of miss forking seem to be at
> B IN MEMORY [e[d*]][e[l[l*]]]
>
> There is no need to save the "e" when forking it is in both structures.
>
> And in the paragraph free version same problem bed is closing two when only need to save one to fork.
>
> B IN MEMORY *2ed*2ell*
>
> Well more debugging ahead, it seem weird it seem to fork correct in most? cases but suddenly it doesn't place the fork of branchtree correct. Probably a substring hold and compared isn't what i thought it was?
Is there some bright person here that can tell me if it is a cascading problem "one change affecting others in structure" or if it is a bug or missed case?
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.javascript
csiph-web