Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Insert algorithms

43 views
Skip to first unread message

Jonas Thörnvall

unread,
Nov 15, 2017, 4:51:46 PM11/15/17
to
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.

Jonas Thörnvall

unread,
Nov 15, 2017, 6:05:52 PM11/15/17
to
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

Jonas Thörnvall

unread,
Nov 17, 2017, 4:27:27 AM11/17/17
to
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.

Jonas Thörnvall

unread,
Nov 21, 2017, 8:37:45 PM11/21/17
to
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>

Jonas Thörnvall

unread,
Nov 21, 2017, 9:13:29 PM11/21/17
to
There is a bug it does not fork correct...

Jonas Thörnvall

unread,
Nov 22, 2017, 7:41:37 AM11/22/17
to
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


Jonas Thörnvall

unread,
Nov 22, 2017, 7:58:56 AM11/22/17
to
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?

Jonas Thörnvall

unread,
Nov 22, 2017, 8:04:51 AM11/22/17
to
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?

0 new messages