Could anyone explain what node means in MySQL?
This one is talking about nested set.
I am reading a document from Codeigniter's wiki and I am not sure what I am supposed to add for $node.
getSubTreeAsHTML (line 704)
Renders the fields for each node starting at the given node
* return: Sample HTML render of tree
string getSubTreeAsHTML (array $node, [array $fields = array()])
* array $node: The node to start with
* array $fields: The fields to display for each node
The code you are looking at is part of BackendPro. The full code of the function can be viewed here.
"Node" in this case refers to a data node of a nested set. Nested sets are nice because they allow you to quickly select a whole branch of a hierarchy with only the starting node.
It looks like the function specified renders part of a tree in HTML starting at the node you specify. The BackendPro interface must render hierarchical data somewhere.
EDIT: Nested sets are not a MySQL-only concept, but there is a good article about nested sets and MySQL here:
http://mikehillyer.com/articles/managing-hierarchical-data-in-mysql/
Related
In XSLT, what is the difference between the "current node" and the "context node"? You can find both terms used here: http://www.w3.org/TR/xslt.
When would you use one or the other? How do you refer to each?
The current node is whatever the template is currently operating on. Normally this happens to also be the context node, but the context node has special meaning within a nested XPath expression (the part in square brackets). There, it refers to whatever node is currently being tested for a match. Hence, the context node changes within the XPath expression, but not the current node.
The context node can be abbreviated with a dot (.) or sometimes left out entirely. This is probably a little confusing, because outside of a nested expression, a dot signifies the current node. (In that case the current node happens to be the context node, so one might say that it is the current node only proximately, and it is more properly called the context node. But even the spec calls it the current node here.)
Since a dot gives you the context node, in a nested XPath expression the user needs a way to refer back to the current node, the one being processed by the current template. You can do this via the current() function.
Distinguishing these two is useful in some cases. For instance, suppose you have some XML like this:
<a>
<b>
<c>foo<footnote fn="1"/></c>
<d>bar</d>
</b>
<b>
<c>baz</c>
<d>aak<footnote fn="2"/></d>
</b>
<b>
<c>eep</c>
<d>blech<footnote fn="2"/></d>
</b>
<footnote-message fn="1">Batteries not included.</footnote>
<footnote-message fn="2">Some assembly required.</footnote>
</a>
Now suppose you want to convert it to LaTeX like this:
foo\footnote{Batteries not included.}
bar
baz
aak\footnote{Some assembly required.}
eep
blech\footnotemark[2]
The trick is the tell whether a footnote has already been used or not. If this is the first time you've encountered the footnote, you want to write a \footnote command; otherwise you want to write a \footnotemark command. You could use XSL code like this:
<xsl:choose>
<xsl:when test="count(preceding::*[./#fn = current()/#fn]) = 0">\footnote{...}</xsl:when>
<xsl:otherwise>\footnotemark[...]</xsl:otherwise>
</xsl:choose>
Here we are comparing the context-node fn attribute (from the results of the preceding::* node-set) to the current-node fn attribute. (You don't actually have to say ./#fn; you could just say #fn.)
So in short, the context node leaves you inside the XPath predicate; the current node reaches outside the predicate, back to the node being processed by the current template.
Context Node
The context node is part of the XPath evaluation context and varies with each location step:
step1 / step2 / step3 / ...
where each step is
axis::node-test[predicate]
Each step is evaluated with respect to the context nodes set by the preceding steps.
Each step then selects nodes that become the context node for following steps.
When evaluating predicate, the context node is the node along axis that has passed node-test.
The context node can be accessed as ..
Current Node
The current node () is part of the XSLT processing model:1
The current node is the node in the source XML document best matched by an XSLT template.
The current node becomes the starting context node for each XPath expression in the matched template.
The current node can be accessed as current() within XPath predicates.
1Although insignificant to understanding the basic difference between context node and current node, note that in XSLT 2.0 the description of the evaluation context has been changed. The concepts of current node and current node list have been replaced by the XPath concepts of context item, context position, and context size.
I have been digging through IBM knowledge center and have returned frustrated at the lack of definition to some of their scripting interfaces.
IBM keeps talking about a containment path used in their id definitions and I am only assuming that it corresponds to an xml element within file in the websphere config folder hierachy, but that's only from observation. I haven't found this declared in any documentation as yet.
Also, to find an ID, there is a syntax that needs to be used that will retrieve it, yet I cannot find a reference to the possible values of 'types' used in the AdminConfig.getid(...) function call.
So to summarize I have a couple questions:
What is the correct definition of the id "heirachy" both for fetching an id and for the id itself?
e.g. to get an Id of the server I would say something like: AdminConfig.getid('/Cell:MYCOMPUTERNode01Cell/Node:MYCOMPUTERNode01/Server:server1'), which would give me an id something like: server1(cells/MYCOMPUTERNode01Cell/nodes/MYCOMPUTERNode01/servers/server1|server.xml#server_1873491723429)
What are the possible /type values in retrieving the id from the websphere server?
e.g. in the above example, /Cell, /Node and /Server are examples of type values used in queries.
UPDATE: I have discovered this document that outlines the locations of various configuration files in the configuration directory.
UPDATE: I am starting to think that the configuration files represent complex objects with attributes and nested attributes. not every object with an 'id' is query-able through the AdminConfig.getid(<containment_path>). Object attributes (and this is not attributes in the strict xml sense as 'attributes' could be nested nodes with a simple structure within the parent node) may be queried using AdminConfig.showAttribute(<element_id>, <attribute_name>). This function will either return the string value of the inline attribute of the element itself or a string list representation of the ids of the nested attribute node(s).
UPDATE: I have discovered the AdminConfig.types() function that will display a list of all manipulatible object types in the configuration files and the AdminConfig.parent() function that displays what nodes are considered parents of the specified node.
Note: The AdminConfig.parent() function does not reveal the parents in order of their hierachy, rather it seems to just present a list of parents. e.g. AdminConfig.parent('JDBCProvider') gives us this exact list: 'Cell\nDeployment\nNode\nServer\nServerCluster' and even though Server comes before ServerCluster , running AdminConfig.parent('Server') reveals it's parents as: 'Node\nServerCluster'. Although some elements can have no parents - e.g. Cell - Some elements produce an error when running the parent function - e.g. Deployment.
Due to the apparent lack of a reciprocal AdminConfig.children() function, It appears as though obtaining a full hierachical tree of parents/children lies in calling this function on each of the elements returned from the AdminConfig.parent(<>) call and combining the results. That being said, a trial and error approach is mostly fruitful due to the sometimes obvious ordering.
I have imported a few nodes with properties via the Cypher CSV import (command below) and the nodes seem to have loaded correctly as I can view them in the REST-API (the data browser). When I execute a MATCH (n) RETURN n query, all of the nodes are displayed in the Results pane, and when I click on one of the nodes the properties are displayed in the left pane of the browser (I would attach a screen shot showing what I am trying to refer to here which would make this issue A LOT more clear and easy to understand, but apparently us neophytes are prohibited from providing such useful information).
However, when I try to query any of the nodes directly, I get no rows returned. By "query the nodes directly" I am referring to querying with a WHERE condition where I ask for a specific property:
MATCH (n)
WHERE n:Type="Idea"
RETURN n
Type is one of the properties of the node. No rows are returned from the query. I can click on the node in the Stream pane to open the properties dialog, and I can see the Type property is clearly "Idea."
Am I missing something? The nodes and properties seemed to have loaded into the DB correctly, but I can't seem to query anything. Is "ID" a restricted term? Do I even need an "ID" property (i thought I read somewhere you shouldn't trust the auto-generated IDs as they aren't guaranteed to be unique over time)?
Import statement used to load the nodes is below:
$ auto-index name, ID
$ import-cypher -i ProjectNodesCSV.csv -o ProjectOut.csv CREATE (n:Project {ID:{ID},Name: {Name}, Type: {Type}, ProjectGroupName: {ProjectGroupName}, ProjectCategoryName: {ProjectCategoryName}, UnifierID: {UnifierID}, StartDate: {StartDate}, EndDate: {EndDate}, CapitalCosts: {CapitalCosts}, OandMCosts: {OandMCosts}}) RETURN ID(n) as ID, n.Name as Name
How do I check using a razor template in Umbraco to determine if the current page is a descendant of a specific node? I'll be using a case statement.
Not sure if those methods still work with the latest version of Umbraco, but with 4.7.1 and DynamicNode there use to be those methods:
#Model.AncestorOrSelf(string nodeTypeAlias)
#Model.AncestorOrSelf(int level)
#Model.AncestorOrSelf(Func<DynamicNode, bool> func)
and those Helper functions:
#Model.IsDescendant(DynamicNode[,valueIfTrue][,valueIfFalse])
#Model.IsDescendantOrSelf(DynamicNode[,valueIfTrue][,valueIfFalse])
If you're using uComponents / uQuery from http://ucomponents.codeplex.com/ you can do something like:
var isChildOf = uQuery.GetCurrentNode().GetAncestorNodes().Where(n => n.NodeTypeAlias == "MyHomePage").First() != null;
(Note: I haven't tried this code, but have similar in production)
A quick and dirty way of doing it would be to check the nodes Path property (I think #Model.Path should get it). This should contain either a comma separate string or an array of numbers (not sure which off the top of my head) of the path from the node back to the root of the site. You can check for your parent node in that property. Which would save on more expensive lookups of nodes using LINQ or uQuery.
I'm in the need of sort of a linked list structure, but if it had indexed access too it would be great.
Is it any way to accomplish that?
EDIT: I'm writing in C, but it may be for any language.
One method of achieving your goal is to implement a random or deterministic skip list. On the bottom level - you have your linked list with your items.
In order to get to elements using indexes, you'll need to add information to the inner nodes - of how many nodes are in the low most level, from this node until the next node on this level. This information can be added and maintained in O(logn).
This solution complexity is:
Add, Remove, Go to index, all work in O(logn).
The down side of this solution is that it is much more difficult to implement than the regular linked list. So using a regular linked list, you get Add, Remove in O(1), and Go to index in O(n).
You can probably use a tree for what you are aiming at. Make a binary tree that maintains the weights of each node of the tree (where the weight is equal to the number of nodes attached to that node, including itself). If you have a balancing scheme available for the tree, then insertions are still O(log n), since you only need to add one to the ancestor nodes' weights. Getting a node by index is O(log n), since you need only look at the indices of the ancestors of your desired node and the two children of each of those ancestors.
For achieving array like indexing in languages like C++, Java, Python, one would have to overload the array indexing operator [] for a class which implements the linked list data structure. The implementation would be O(n). In C since operator overloading is not possible, hence one would have to write a function which takes the linked list data structure and a position and returns the corresponding object.
In case a faster order access is required, one would have to use a different data structure like the BTree suggested by jprete or a dynamic array (which automatically grows as and when new elements are added to it). A quick example would be std::vector in C++ standard library.
SQL server row items in the clustered index are arranged like so:
.
/ \
/\ /\
*-*-*-*
The linked list is in the leaves (*-*-*). The linked list is ordered allowing fast directional scanning, and the tree serves as a `road-map' into the linked-list. So you would need a key-value pair for your items and then a data structure that encapsulates the tree and linked list.
so your data structure might look something like this:
struct ll_node
{
kv_pair current;
ll_node * next;
};
struct tree_node
{
value_type value;
short isLeaf;
union
{
tree_node * left_child;
kv_pair * left_leaf;
}
union
{
tree_node * right_child;
kv_pair * right_leaf
}
};
struct indexed_ll
{
tree_node * tree_root;
ll_node * linked_list_tail;
};