Permalink
Browse files

refucktoring: thrill to start, relief to finish

  • Loading branch information...
gritzko committed Nov 1, 2010
1 parent 361942d commit 85a99c3870472a2f7052a8f7eb4ccdce0eea920d
Showing with 0 additions and 144 deletions.
  1. +0 −144 ctre.js
View
144 ctre.js
@@ -270,21 +270,6 @@ CT.getYarnLength = function (weft2,yarnid) {
return pos!=-1 ? weft2[pos+1] : '/';
}
-/*CT.prototype.re_form2 = /../g;
-CT.prototype.re_w2diff = /(..)\1|(.).(\2).|(.)./g;
-CT.prototype.re_notinset = "[^$S]";
-/** Compare two weft2s according to the weftI-ordering (see the paper). *
-CT.prototype.compareWeft1 = function (weft2a,weft2b) {
- var split = (weft2a+weft2b).match(this.re_form2);
- var sorted = split.sort().join('');
- var diff = sorted.replace(this.re_w2diff,"$3$4");
- if (!diff)
- return 0;
- var re_srch = CT.re( this.re_notinset, {'S':CT.escapeMeta(diff)} );
- var srt_diff = this.roster.getSortedYarnIds().replace(re_srch,"");
- var win = srt_diff.charAt(0);
- return CT.getYarnLength(weft2a,win) > CT.getYarnLength(weft2b,win) ? 1 : -1;
-} replaced by weftII which is lexicographically OK */
CT.prototype.getYarnLength = function (yarnid) {
return CT.getYarnLength(this.getWeft2(),yarnid);
@@ -388,135 +373,6 @@ CT.prototype.addPatch5c = function (patch5c) {
}
-
-
-/*CT.prototype.re_chunk =
- CT.re("(?:$a$4)+|($x)..(.).(?:\\1..\\2.)*|$M..(?:(..)$M\\3)*..|$m.{4}",CT.$); // the Spui regex
-/** The only method that mutates weave5c. Takes an array of atoms (patch5c),
- splits it into causality chains, applies chains to the weave. *
-CT.prototype.addPatch5c = function (patch5c) { // append-only order is mandatory
- if (!patch5c) return;
- this.text5c = this.text3 = this.text1 = this.weave3 = undefined;
- // check whether yarns are known
- var chunks = patch5c.match(this.re_chunk).reverse();
- var fails = 0;
- while (chunks.length && fails<chunks.length) {
- var chunk = chunks.pop();
- // check for causal deps, duplicate content
- var prev = String.fromCharCode(chunk.charCodeAt(4)-1);
- var deps = chunk.substr(1,2) + (prev=='/' ? '' : chunk[3] + prev);
- if (!CT.isCover(this.getWeft2(),deps)) {
- fails++;
- chunks.unshift(chunk);
- continue;
- }
- if (this.getYarnLength(chunk[3])>=chunk[4])
- throw "duplicate content"; // TODO cut n paste
- if (chunk[0]==='\u0008') { // deletion
- this.weave5c = this.addDeletionChunk5c(chunk);
- } else if (chunk[0]==='\u0006') { // awareness
- this.weave5c += chunk;
- } else if (chunk[0]=='\u007F') {
- this.weave5c = this.addUndeletionChunk5c(chunk);
- } else if (chunk[0]=='\u0001' || chunk[0]=='\u0004') {
- throw "begin/end chars in a patch";
- } else {
- this.weave5c = this.addChunk5c(chunk) ||
- this.addChunk5cHardcore(chunk);
- }
- var fack = this.weave5c.indexOf('\u0006');
- if (fack!=-1 && fack<this.weave5c.indexOf('\u0004'))
- alert('misplaced ack');
- fails = 0;
- var yarn_id = chunk[3];
- if (this.awareness)
- this.awareness[yarn_id] = undefined;
- var new_ids = chunk.replace(this.re_form5c,"$3");
- this.weft2 = CT.dryWeft2(this.weft2+new_ids);
- this.deps4c = undefined;
- }
- if (chunks.length>0)
- alert('patch fails');
-}
-
-
-
-CT.prototype.re_siblings = ".$R..(?:.{5})*?(?=.$R..|$)";
-/** In case optimizations fail, the weave is patched using this method.
- It involves complex parsing and building of closed weft1, i.e. is
- is expensive. On the bright side, it is rarely invoked. *
-CT.prototype.addChunk5cHardcore = function (chunk5c) {
- var root = chunk5c.substr(1,2);
- var head = chunk5c.substr(3,2);
- var split = this.weave5c.match(re_split);
- if (!split) throw "cannot find the attachment point";
- var beginning = split[1];
- var attach = split[2];
- var caused = split[3];
- var end = split[4];
- var head_aw_weft = this.closeWeft2(head+chunk5c.substr(1,2));
- var siblings = caused.match( CT.re( this.re_siblings, {'R':root}, 'gm') );
- if (!siblings) {
- alert("why?");
- }
- var i=0;
- for(; i<siblings.length; i++) {
- var sib_aw_weft = this.closeWeft2(siblings[i].substr(3,2));
- if (this.compareWeft1(head_aw_weft,sib_aw_weft)==1)
- break;
- }
- siblings.splice(i,0,chunk5c);
- return beginning + attach + siblings.join('') + end;
-}
-
-CT.prototype.re_patch =
- "^($5*?)($1$2$C(?:$x$4)*)($1$2(?:$A).*)$";
-/** The streamlined weave patching method. May fail in case of unaware
- (i.e. concurrent) siblings. *
-CT.prototype.addChunk5c = function (chunk5c) {
- var cause = chunk5c.substr(1,2);
- var head = chunk5c.substr(3,2);
- var aware = this.getYarnAwareness(head[0]);
- var re_aware = CT.getFiltre(aware+cause);
- var re_find = CT.re(this.re_patch, {'C':CT.escapeMeta(cause),'A':re_aware}, 'm');
- var new_weave5c = this.weave5c.replace(re_find,"$1$2"+chunk5c+"$3");
- if (new_weave5c.length!=this.weave5c.length+chunk5c.length)
- return null;
- return new_weave5c;
-}
-
-//CT.prototype.re_findvictim = /((?:.....)*?...($M))((?:.....)*?)(?=$|...($M))/g;
-CT.prototype.re_form5c = CT.re("(.)($2)($2)");
-CT.prototype.addDeletionChunk5c = function (chunk5c) {
- var head = chunk5c.substr(3,2);
- var ids = CT.escapeMeta(chunk5c.replace(this.re_form5c,"$2"));
- var re_ids = ids.match(CT.re_filt).join('|');
- var re_victim = new RegExp("((?:.....)*?...("+re_ids // PAIN
- +"))((?:.....)*?)(?=$|...("+re_ids+"))","gm");
- var maparr = chunk5c.replace(this.re_form5c,"-$2-$3").split('-').reverse();
- maparr.pop();
- var map = {};
- while (maparr.length)
- map[maparr.pop()] = maparr.pop();
- function delatom (match,head,id,tail) {
- return head+'\u0008'+id+map[id]+tail;
- }
- var w5c = this.weave5c.replace (re_victim,delatom);
- return w5c;
-}
-
-CT.prototype.re_find_undo = "($5*?)($<$C)($A)($5*?)(?=$|.$2$C)";
-CT.prototype.addUndeletionChunk5c = function (chunk5c) {
- var head = chunk5c.substr(3,2);
- var aw = this.closeWeft2(head); // TODO optimize FIXME no shared ids
- var aw_filtre = "(?:"+CT.getFiltre(aw)+")";
- var ids = CT.escapeMeta(chunk5c.replace(this.re_form5c,"$2"));
- var re_ids = "(?:"+ids.replace(CT.re_filt,"|$&").substr(1)+")";
- var re = CT.re(this.re_find_undo, {'A':aw_filtre,'C':re_ids});
- var w5c = this.weave5c.replace(re,"$1\u007F$3"+head+"$2$3$4");
- return w5c;
-}*/
-
CT.re_filter2 = "$F|(..)";
/** returns whether first weft covers the second */
CT.isCover = function (weft2sup, weft2sub) {

0 comments on commit 85a99c3

Please sign in to comment.