GB2422924A - Determining derived relationships in a hierarchical structure - Google Patents
Determining derived relationships in a hierarchical structure Download PDFInfo
- Publication number
- GB2422924A GB2422924A GB0502281A GB0502281A GB2422924A GB 2422924 A GB2422924 A GB 2422924A GB 0502281 A GB0502281 A GB 0502281A GB 0502281 A GB0502281 A GB 0502281A GB 2422924 A GB2422924 A GB 2422924A
- Authority
- GB
- United Kingdom
- Prior art keywords
- item
- data
- data item
- tree structure
- tree
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Withdrawn
Links
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
- G06F9/44—Arrangements for executing specific programs
- G06F9/448—Execution paradigms, e.g. implementations of programming paradigms
- G06F9/4488—Object-oriented
- G06F9/4492—Inheritance
Landscapes
- Engineering & Computer Science (AREA)
- Software Systems (AREA)
- Theoretical Computer Science (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Debugging And Monitoring (AREA)
Abstract
In a data processing system having a plurality of data items as a tree structure so that a data item lower in the tree structure is related by a path through the tree structure to one or more data items at respective higher levels in the tree structure, each data item has an associated numerical item identifier and a tree identifier representing the position of that data item in the tree structure. The tree identifier for a data item is dependent upon a mathematical combination of the item identifiers for data items in the path relating to that data item and the item identifiers and the mathematical combination are arranged so as to allow a test dependent only on the tree identifier of a data item under test and the item identifier of a data item higher in the tree structure to determine whether the data item under test lies on a path relating to that data item higher in the tree structure. Tree identifiers may be the product of higher prime number item identifiers, or may be the sum of binary item identifiers of suitably increasing magnitude as the hierarchy descends.
Description
1 2422924
DATA PROCESSING
This invention relates to data processing.
In object-oriented (00) programming, so-called objects are created with a given "type". The types available are defined (usually) as a tree, or hierarchy. There is typically one base type from which (one or more) more specialised types are derivedlinherited, and yet more types are derived in turn from those. An object of a heavily derived type inherits all the properties of each parent type in turn, and can in some circumstances be treated as if it is any type from which is derives. It is therefore common in 00 programming for the programmer to be expected to handle an object knowing only that it derives in some way from a base type. If the programmer wants to use this object as a more derived type, it must first be tested to check if the object is of (or is derived from) the type containing the specific functionality required.
A traditional solution is for each object to store locally it's own type, and for each type to know which type it is derived from. So when an object is tested, there is an iterative process of comparing the object's type with the type being searched for, and if there is no match, moving on to the immediate parent type. This process only ends if a match it found, or there are no more parent types. This means that the worst case is found when testing for a rare type, and where many objects exist of heavily-derived types, because the entire list of parents is checked for each of many objects in order to reject them. Accordingly this is a variable length process with many potential performance penalties in a real-world situation.
This invention provides a data processing system having a plurality of data items; .: the data items being arranged as a tree structure so that a data item lower in the tree * structure is related by a path through the tree structure to one or more data items at * respective higher levels in the tree structure; and each data item having an associated numerical item identifier and a tree identifier representing the position of that data item in the tree structure; * inwhich: * * the tree identifier for a data item is dependent upon a mathematical combination of * *. S the item identifiers for data items in the path relating to that data item; and the item identifiers and the mathematical combination are arranged so as to allow a test dependent only on the tree identifier of a data item under test and the item identifier of a data item higher in the tree structure to determine whether the data item under test lies on a path relating to that data item higher in the tree structure.
Various further respective aspects and features of the invention are defined in the appended claims.
Embodiments of the invention can provide a method of testing an object for inheritance, with only a single "cheap" (having a low processing overhead) and fixed- overhead check. Preferably, the technique assigns a unique prime number to each individual class. Then there is assigned to each class (e.g. in depth order) a number which is the product of it's own prime number and the prime numbers associated with each of the classes from which it is derived. The product of the base or root class can be initialised to 1 (although any prime would do), as all classes must derive from this and an explicit test is not required.
The test for an object against a given type is then to check if the object's product is exactly divisible by the type's prime. If it is, it must be a derived class, otherwise it can't be.
Embodiments of the invention will now be described with reference to the accompanying drawings in which: Figure 1 schematically illustrates the internal structure of a data processing system; Figure 2 schematically illustrates a data processing system; Figure 3 is a schematic flow chart illustrating operations involved in preparing and executing computer program code; Figure 4 schematically illustrates a tree structure of object types; Figure 5 is a schematic flow chart illustrating part of a runtime initialisation process; and Figure 6 schematically illustrates a detection process. *
: Referring now to Figure 1, a data processing system comprises a bus 10 to which are connected a processor (CPU) 20, read only memory (ROM) 30, random access memory (RAM) 40, input / output (I/O) logic 50 (e.g. including a network interface to a network or internet connection 70) and a graphics processor (GP) 60. Of course, other functionality (such as disk storage) may be provided.
Figure 2 schematically illustrates the external appearance of such a system, generally * :: . having a system unit housing much or all of the functionality shown in Figure 1, a display and at least one user interface device 120 such as a keyboard, mouse or (as in the present case) a games controller.
In terms of a process for producing and executing 00 program code, the data processing system may take part in various different stages of that process. The overall process is shown schematically in Figure 3.
Referring to Figure 3, at a step 200 a user prepares so-called source code. This may be entered via a keyboard or a visual interface, and defines operations to be executed in a form that is readable by the user. But in order for the program to be executed (e.g. by the CPU 20 of Figure 1) the code has to be compiled at a step 210. This well-established process involves converting the human-readable program into machineoperable program code, and at the same time linking together different functional units within the program to operate in a consistent manner.
The compilation process generates so-called object code, which can then be stored (e.g. in ROM or on a removable disk medium - not shown) or transmitted (e. g. via an internet connection) for subsequent execution by the same or another processor.
At run time, in a simplified view a first step is a run time preparation step 220, during which (amongst other things) a process described below with reference to Figure 5 is executed. Then execution of the remainder of the object code takes place (a step 230).
During that execution, a process described below with reference to Figure 6 may take place if and when required.
Figure 4 schematically illustrates a tree structure of object types. As mentioned above, each object has an associated "type", which in this embodiment are defined as a tree or hierarchy. There is one base type 300 from which more specialised types are derivedlinherited, and yet more types are derived in turn from those. An object of a heavily derived type inherits all the properties of each parent type in turn, and can in some circumstances be treated as if it is any type from which is derives. It is therefore common in 00 programming for the programmer to be expected to handle an object knowing only that L: it derives in some way from a base type. If the programmer wants to use this object as a more derived type, it must first be tested to check if the object is of(or is derived from) the type containing the specific functionality required.
So, in Figure 4, two types 310, 320 are derived from the base type 300. A type 330 is *S.
derived from types 346, 336, 324, 310 and 300, and inherits all the properties of those :. intervening types. * *..
* ** The deepest tree structure has typically about eight levels. So, the previously * *** proposed technique described in the introduction for checking whether one type is derived from another can involve many separate and detailed checks, which is expensive in terms of processor requirements.
The techniques described here allow the test to be made much more quickly and cheaply (in terms of processor resources) by assigning numerical values to each type in such a way as to allow a test dependent only on an identifier of a type under test and a value associated with a type higher in the tree structure to determine whether the type under test is derived from the type higher in the tree structure.
In one embodiment, prime numbers are assigned to each type in the tree. Each type is also assigned the product of all of the prime numbers associated with types from which it is derived. These steps may be taken (as steps 400, 410 respectively) during a runtime preparation stage of executing the program. This can be (for example) implemented as part of the compiled software itself, as an automated function to take place at run time, or as a callable library routine which is accessed by the compiled software. So, in relation to the example shown in Figure 4, a set of numbers might be: Type (node) - ref on Figure 4 Prime number Product 300 1 (root of structure) 1 310 2 2 320 3 3 322 5 10 324 7 14 326 11 33 328 13 39 332 17 85 334 19 95 336 23 322 a * * S * 338 29 406 **SS* 340 31 1209 * 342 37 1443 a, *. 344 41 13202 346 43 13846 348 47 650762 S... _____________________________________ - ________________________ 330 53 733838 In order to test whether (for example) the type 348 is derived from the type 310, it is simply necessary to check whether the product associated with the type 348 (i.e. 650762) has the prime number associated with the type 310 (i.e. 2) as a factor. It does.
This test is schematically illustrated in the flow chart of Figure 6. At a step 420, the prime number associated with the (potential parent) type is detected. At a step 430, the product value associated with the (potentially derived) type is detected. Then, at a step 440, a simple test is carried out to detect whether the prime number is a factor of the product.
In another embodiment, an additive combination can be used. Each type is assigned a number and a sum of the numbers relating to types from which it derives. Preferably, each of the numbers is selected from a group such that it is greater than a sum of all smaller numbers in that group. There follows an example, using binary arithmetic: Type (node) - ref on Figure 4 Type identifier (binary) Sum (binary) 300 1 (root of structure) 1 310 10 11 320 100 101 322 1000 1011 324 10000 10011 326 100000 100101 328 1000000 1000101 332 10000000 10001011 334 100000000 100001011 336 1000000000 1000010011 338 10000000000 10000010011 340 100000000000 100001000101 * . a a 342 1000000000000 1000001000101 *S,.
S
344 10000000000000 10001000010011 * : 346 100000000000000 100001000010011 * S. ____________________________ _________________________ 348 1000000000000000 1000000000000000 330 10000000000000000 10100001000010011
SS
* *** In this example, a simple software test can be carried out to detect whether a particular bit position (corresponding to the identifier associated with a potential parent type) is occupied in the sum. This test may be included as part of the compiled software itself, or as a callable library routine which can be used by the compiled software.
It will be clear that although the present technique has been described with reference to object types in 00 programming, it could be applied to other data handling techniques in which it is desired to be able to carry out a quick and elegantly simple test to detect whether one node lies on a path through the tree structure passing through another node.
The embodiments of the invention described above may be implemented, at least in part, using software-controlled data processing apparatus. It will be appreciated that a computer program providing such software control and a storage medium (e.g. an optical disk) or a transmission medium (e.g. the internet or network connection described above) by which such a computer program is provided are envisaged as aspects of the present invention.
There follows an example section of source code which, when compiled and executed, operates to establish a hierarchy of classes, each class having an associated prime number and a product value. This simplified example shows the derivation of one of each of a "base" class, a "derived" class and an "other" class, and ends with an example of a test which can be applied to determine the nature of the various classes. Comments are indicated by the "II" delimiter in some of the lines. a * * a S.. *
S SSa *. S * a, * .. *Sa
S S. * S *
* a. q
I S... 1S * . I
* : * * *. :.e * * **. * : ** * . * I * I SI. * * * * I * mt primes[]={2,3,5,7,l 1,13,17,19,23,29); I/Define some primes (could start at 1) class Element II The Element class does most of the work protected: Element(const Element &p); II Protected constructor to stop accidental duplication public: Element(Element *parent) { II The real constructor requires a parent element (0 for the base element) m_parentparent; mnextElementmfirstElement; II Add this element to the global list of elements mfirstElementthis; m_prime=primes[m_curlD++]; II Assign the next available prime void process() II This function sets up the products for all the types if('m_parent) {mproductmprime;} II Trivial case for the base type else if(Im_parent_>mjroduct) m_parent_>processO; II First we need to make sure any parent types are initialised if(m_product && mparent) mproduct=mparent>mjroduct*m_prime; I/If we haven't done so already, multiply the parent's product with our own prime if(m_nextElement) m_nextElement>processO; II Process any other elements we haven't got around to yet static processFirst() {m_firstElement-> processO;} II Kick off the processing at the first element boo! isTypeOf(Element *type) (return 0==(mJ,roduct%type->mjrime);} II Trivial function to check ancestry - note we do not iterate or recurse to the parent protected: Element *mparent; II Pointer to the element for the parent class static Element 1m_firstElement; II The first element in the list Element *mnextElement; II The next element in the list static mt m_curlD, If A counter for looking up the next available prime mt mprime; II Our own prime mt mproduct; II The product of primes up to the base class class Base II A simple base class public: * * : : * * : * : * * . * : ** * a * * a S.. * * * *
V
static Element rn_element; II All classes must have an Element associated with them virtual Element *getType() { return &m_element;} I/Any derived classes will override this function to return their own element bool isTypeOf(Element *el) {return getTypeo->isTypeOgel);} II This is a shortcut to the type-checking function class Derived: public Base II Define a simple derived class public: static Element rn_element; II The element for this class virtual Element *getType() { return &m_element;} II And the overridden type function class Other: public Base II Define another derived class public: static Element rn_element; II Another unique element virtual Element *getType() { return &m_elernent;} II Once again override the type function #define TYPE(a) &a: :m_element II This is just to make the code neater...
I/Instantiate the static members declared above. 00 mt Element::mcurlD; Element *Element: :mfirstElement; Element Base: :m_element(O); Element Derived: :melement(TYPE(Base)); Element Other: :m_element(TYPE(Base)); void main(lnt argc,char **argv) Element::processFirstO; II This has to be called at application start-up (after all the elements have been created) Base a; II Make one object of each class Derived b; Other c; bool t=c. isTypeOf(TYPE(Other)); II This should return true, as object c really is an "Other" object bool fc.isTypeOf(TYPE(Derived)); II This should return false, as object c is not derived from "Derived"
Claims (13)
1. A data processing system having a plurality of data items; the data items being arranged as a tree structure so that a data item lower in the tree structure is related by a path through the tree structure to one or more data items at respective higher levels in the tree structure; and each data item having an associated numerical item identifier and a tree identifier representing the position of that data item in the tree structure; in which: the tree identifier for a data item is dependent upon a mathematical combination of the item identifiers for data items in the path relating to that data item; and the item identifiers and the mathematical combination are arranged so as to allow a test dependent only on the tree identifier of a data item under test and the item identifier of a data item higher in the tree structure to determine whether the data item under test lies on a path relating to that data item higher in the tree structure.
2. A system according to claim 1, in which: the system is an objectoriented data processing system; and the data items are object types which are derived from one or more data items at respective higher levels in the tree structure.
3. A system according to claim 1 or claim 2, in which the item identifiers are dependent upon respective different prime numbers. *S.S
S S...
*
4. A system according to claim 3, in which the tree identifier for a data item is S * * * .. dependent upon a product of the item identifier for that data item and item identifiers for data items higher in the tree to which that data item is related by the path. * S * 5.
5. A system according to claim 1 or claim 2, in which: the item identifiers are dependent upon numerical values selected from a group of possible values arranged such that each numerical value in the group is larger a sum of all smaller numerical values in the group; and the tree identifier for a data item is dependent upon an additive combination of the item identifier for that data item and item identifiers for data items higher in the tree to which that data item is related by the path.
6. A system according to any one of the preceding claims, comprising means for applying the test to the tree identifier of a data item under test and the item identifier of a data item higher in the tree structure to determine whether the data item under test lies on a path relating to that data item higher in the tree structure.
7. A data processing system substantially as hereinbefore described with reference to the accompanying drawings.
8. A data processing method for handling a plurality of data items; the data items being arranged as a tree structure so that a data item lower in the tree structure is related by a path through the tree structure to one or more data items at respective higher levels in the tree structure; and each data item having an associated numerical item identifier and a tree identifier representing the position of that data item in the tree structure; the method comprising the steps of: setting the tree identifier for a data item to be dependent upon a mathematical combination of the item identifiers for data items in the path relating to that data item; the item identifiers and the mathematical combination being arranged so as to allow a test :..: . * dependent only on the tree identifier of a data item under test and the item identifier of a data item higher in the tree structure to determine whether the data item under test lies on a path relating to that data item higher in the tree structure. * * * *
9. A data processing method substantially as hereinbefore described with reference to the accompanying drawings.
S * ,*
10. Computer software having program code for carrying out a method according to claim 8 or claim 9.
11. A medium by which software according to claim 10 is provided.
12. A medium according to claim 11, the medium being a storage medium.
13. A medium according to claim 11, the medium being a transmission medium. * I * I. * II..
I IIl I. * I *
I I. I * 1*a
II
I * SI.
Priority Applications (2)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
GB0502281A GB2422924A (en) | 2005-02-04 | 2005-02-04 | Determining derived relationships in a hierarchical structure |
PCT/GB2006/000383 WO2006082424A1 (en) | 2005-02-04 | 2006-02-03 | Data processing |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
GB0502281A GB2422924A (en) | 2005-02-04 | 2005-02-04 | Determining derived relationships in a hierarchical structure |
Publications (2)
Publication Number | Publication Date |
---|---|
GB0502281D0 GB0502281D0 (en) | 2005-03-09 |
GB2422924A true GB2422924A (en) | 2006-08-09 |
Family
ID=34307947
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
GB0502281A Withdrawn GB2422924A (en) | 2005-02-04 | 2005-02-04 | Determining derived relationships in a hierarchical structure |
Country Status (2)
Country | Link |
---|---|
GB (1) | GB2422924A (en) |
WO (1) | WO2006082424A1 (en) |
Cited By (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
WO2011081580A1 (en) * | 2009-12-29 | 2011-07-07 | Telefonaktiebolaget Lm Ericsson (Publ) | Method and arrangement for data storage |
Citations (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US5187786A (en) * | 1991-04-05 | 1993-02-16 | Sun Microsystems, Inc. | Method for apparatus for implementing a class hierarchy of objects in a hierarchical file system |
US6480856B1 (en) * | 1995-10-20 | 2002-11-12 | Microsoft Corporation | Method and system for implementing software objects |
Family Cites Families (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US5267349A (en) * | 1990-03-06 | 1993-11-30 | Digital Equipment Corporation | Fast determination of subtype relationship in a single inheritance type hierarchy |
US6714991B1 (en) * | 1998-03-23 | 2004-03-30 | Sun Microsystems, Inc. | Method and apparatus for implementing fast subclass and subtype checks |
-
2005
- 2005-02-04 GB GB0502281A patent/GB2422924A/en not_active Withdrawn
-
2006
- 2006-02-03 WO PCT/GB2006/000383 patent/WO2006082424A1/en not_active Application Discontinuation
Patent Citations (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US5187786A (en) * | 1991-04-05 | 1993-02-16 | Sun Microsystems, Inc. | Method for apparatus for implementing a class hierarchy of objects in a hierarchical file system |
US6480856B1 (en) * | 1995-10-20 | 2002-11-12 | Microsoft Corporation | Method and system for implementing software objects |
Non-Patent Citations (3)
Title |
---|
'Le Chaud Lapin', 20/6/2004, "Re: enum and Prime Numbers For Taxonomic Indication", comp.lang.c++.moderated (Google Groups) [online]. Available from: http://groups.google.co.uk [Accessed 5/4/2005] * |
'Le Chaud Lapin', 21/6/2004, "Re: enum and Prime Numbers For Taxonomic Indication", comp.lang.c++.moderated (Google Groups) [online]. Available from: http://groups.google.co.uk [Accessed 5/4/2005] * |
'Le Chaud Lapin', 7/10/2004, "Re: Is this antenna article serious?", sci.electronics.design (Google Groups) [online]. Available from: http://groups.google.co.uk [Accessed 5/4/2005] * |
Cited By (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
WO2011081580A1 (en) * | 2009-12-29 | 2011-07-07 | Telefonaktiebolaget Lm Ericsson (Publ) | Method and arrangement for data storage |
Also Published As
Publication number | Publication date |
---|---|
WO2006082424A1 (en) | 2006-08-10 |
GB0502281D0 (en) | 2005-03-09 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
US10740115B2 (en) | Structural identification of dynamically-generated, pattern-based classes | |
US20030200533A1 (en) | Method and apparatus for creating software objects | |
US7613953B2 (en) | Method of converting a regression test script of an automated testing tool into a function | |
US8281292B2 (en) | Rapid application development | |
US10216501B2 (en) | Generating code in statically typed programming languages for dynamically typed array-based language | |
US9311111B2 (en) | Programming environment with support for handle and non-handle user-created classes | |
US6993682B2 (en) | Automated test generation | |
Wolczko | Semantics of object-oriented languages | |
US6704802B1 (en) | Method and system for communicating between independent software modules | |
GB2422924A (en) | Determining derived relationships in a hierarchical structure | |
US20230251838A1 (en) | User customizable compiler attributes for code optimization | |
Alic et al. | Comparative analysis of functional and object-oriented programming | |
US20230251837A1 (en) | User customizable compiler attributes for code checking | |
Bucanek et al. | Learn Objective-C for Java Developers | |
Sharan et al. | Scripting in Java | |
Wojszczyk et al. | Performance analysis of extracting object structure from source code | |
Hunt | Python Modules and Packages | |
Alankus et al. | Java Fundamentals: A fast-paced and pragmatic introduction to one of the world's most popular programming languages | |
CA2875046A1 (en) | Efficient compilation system and method for virtual function table creation | |
Merelo et al. | Roles and Classes: Bundling Code and Data in the Same Block and Reusing It Is the Main Part Roles and Classes Play in So-Called Object-Oriented Languages | |
Painchaud et al. | On the implementation of a stand-alone Java/sup TM/bytecode verifier | |
Friesen et al. | Discovering Classes and Objects | |
CN115291987A (en) | Page generation method and device, electronic equipment and storage medium | |
Oetsch et al. | Extending object-oriented languages by declarative specifications of complex objects using answer-set programming | |
Layka et al. | Introduction to Java |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
WAP | Application withdrawn, taken to be withdrawn or refused ** after publication under section 16(1) |