Skip to content

Instantly share code, notes, and snippets.

@ku
Created February 18, 2009 04:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ku/66201 to your computer and use it in GitHub Desktop.
Save ku/66201 to your computer and use it in GitHub Desktop.
manipulate ubigraph from firefox
function Ubigraph(u) {
this.endpoint = u || "http://127.0.0.1:20738/RPC2";
}
Ubigraph.prototype._invoke = function (xml) {
var dec = '<?xml version="1.0" encoding="UTF-8"?>';
var body = dec + xml.toSource();
var r = new XMLHttpRequest();
r.open("POST", this.endpoint, false);
r.setRequestHeader( "Content-Type", "text/xml" )
r.send( body);
return new XML ( r.responseText.replace(dec, '') );
}
Ubigraph.prototype.clear = function () {
var xml = this._invoke( <><methodCall>
<methodName>ubigraph.clear</methodName>
<params>
<param><value><i4>0</i4></value></param>
</params>
</methodCall></>
);
}
Ubigraph.prototype.new_vertex = function () {
var xml = this._invoke( <><methodCall>
<methodName>ubigraph.new_vertex</methodName>
<params>
</params>
</methodCall></>
);
return parseInt(xml..i4);
}
Ubigraph.prototype.set_edge_attribute = function (v, attr, value) {
var xml = this._invoke( <><methodCall>
<methodName>ubigraph.set_edge_attribute</methodName>
<params>
<param><value><i4>{v}</i4></value></param>
<param><value><string>{attr}</string></value></param>
<param><value><string>{value}</string></value></param>
</params>
</methodCall></>
);
return parseInt(xml..i4);
}
Ubigraph.prototype.set_vertex_attribute = function (v, attr, value) {
var xml = this._invoke( <><methodCall>
<methodName>ubigraph.set_vertex_attribute</methodName>
<params>
<param><value><i4>{v}</i4></value></param>
<param><value><string>{attr}</string></value></param>
<param><value><string>{value}</string></value></param>
</params>
</methodCall></>
);
return parseInt(xml..i4);
}
Ubigraph.prototype.new_edge = function (v1, v2){
var xml = this._invoke( <><methodCall>
<methodName>ubigraph.new_edge</methodName>
<params>
<param><value><i4>{v1}</i4></value></param>
<param><value><i4>{v2}</i4></value></param>
</params>
</methodCall></>
);
return parseInt(xml..i4);
}
/*
try {
var u = new Ubigraph();
u.clear();
var vt = [];
var c = 100;
for(var i =0 ; i < c;i++) {
vt[i] = u.new_vertex();;
}
for(var i =0 ; i < c;i++) {
var n = Math.floor(Math.random()*c);
var m = Math.floor(Math.random()*c);
var e1 = u.new_edge(vt[n], vt[m]);
}
}catch(e){e}
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment