What Data Structures can't be implemented in C but in Java? - data-structures

Can anyone tell me what data structure i can't use in C language but in Java.
Can anyone tell me what data structure i can't use in C language but in Java.

Any data structure can be build in any language. But, java already have predefined collection of data structures. For example, java already have collections for LinkedLists,HashMaps,Trees... But in C, you have to implement on your own if you need.

Related

is there a generic query language for arbitrary sets independent from a programming language?

I'm looking for a way to define queries on sets independently from a programming language or the kind of sets.
In detail this would be a language definition and implementations for common languages like Java, C++, Python etc.
As commented I'm not looking for a database or any implementation of a set-representation but only a way to define a query for elements from e.g. a std::set/vector a Python set() or any linear structure which can be seen as a set.
A close example would be something like jLinq but without being tied to JSON or javascript and with a well defined string representation.
Of course without knowing the kind of data structure you would have to implement any conditional filter for every problem and every programming language, but the way you construct query strings and how you evaluate them would be clear and you would not have to write parsers.
So what I'd like to write in Java or C++ is something like
q = query()
.created_after("14.03.2010")
.and(contains("hello")
.or(contains("hallo")))
.sort("caption")
or written as a string:
"(created_after("14.03.2010") and ( contains("hello") or contains("hallo"))) sort("caption")"
(this is not thought through - just to show what an interface could look like)
A good example for a different problem would be JSON or XML: clear language definition and parsers/tools for any platform or programming language.
I know this is an old question, but I think I know what you mean and I was actually looking for something similar. What you need is a "search query parser".
I found search-query-parser for nodejs (I'm not the author). Haven't tried it yet but looks promising.The example in the docs is very illustraring, you would receive an input string from the UI
from:hi#retrace.io,foo#gmail.com to:me subject:vacations date:1/10/2013-15/04/2014 photos
And the library would parse it to a structured json object
{
from: ['hi#retrace.io', 'foo#gmail.com'],
to: 'me',
subject: 'vacations',
date: {
from: '1/10/2013',
to: '15/04/2014'
},
text: 'photos'
}
And the from that object you could construct and issue a query command to your database. As you can see it handles lists and ranges. Right away I can't see any boolean operator (AND,OR) but I guess could be easily implemented.
Hope this helps.
RSQL is a good option these days. There are plenty of parsers available and the queries are URL friendly.

Recursive logic for parsing string into complex boolean?

I'm sure this has been done before, I just can't find it.
I need to turn something like, "((A OR B) AND C) OR D" into a database query for an attribute. Specifically I'm using Ruby Sequel. Can anyone point me at an example or utility or something that will keep me from reinventing the wheel?
You can define a grammar using ANTLR and automatically generate a Ruby parser for those type of strings. ANTLR is a parser generator and it allows you to define a grammar for a language (such as a the boolean language that you described).
After parsing, you can specify what actions need to be taken to build the desired data structure (in your case a tree data structure that captures the structure of the query).
This is not particularly a Ruby problem as ANTLR can also generate parsers for other languages. In your case it would produce a Ruby parser that you can integrate into your application to parse the strings and to produce the data structure that you need.

Abstracting away from data structure implementation details in Clojure

I am developing a complex data structure in Clojure with multiple sub-structures.
I know that I will want to extend this structure over time, and may at times want to change the internal structure without breaking different users of the data structure (for example I may want to change a vector into a hashmap, add some kind of indexing structure for performance reasons, or incorporate a Java type)
My current thinking is:
Define a protocol for the overall structure with various accessor methods
Create a mini-library of functions that navigate the data structure e.g. (query-substructure-abc param1 param2)
Implement the data structure using defrecord or deftype, with the protocol methods defined to use the mini-library
I think this will work, though I'm worried it is starting to look like rather a lot of "glue" code. Also it probably also reflects my greater familiarity with object-oriented approaches.
What is the recommended way to do this in Clojure?
I think that deftype might be the way to go, however I'd take a pass on the accessor methods. Instead, look into clojure.lang.ILookup and clojure.lang.Associative; these are interfaces which, if you implement them for your type, will let you use get / get-in and assoc / assoc-in, making for a far more versatile solution (not only will you be able to change the underlying implementation, but perhaps also to use functions built on top of Clojure's standard collections library to manipulate your structures).
A couple of things to note:
You should probably start with defrecord, using get, assoc & Co. with the standard defrecord implementations of ILookup, Associative, IPersistentMap and java.util.Map. You might be able to go a pretty long way with it.
If/when these are no longer enough, have a look at the sources for emit-defrecord (a private function defined in core_deftype.clj in Clojure's sources). It's pretty complex, but it will give you an idea of what you may need to implement.
Neither deftype nor defrecord currently define any factory functions for you, but you should probably do it yourself. Sanity checking goes inside those functions (and/or the corresponding tests).
The more conceptually complex operations are of course a perfect fit for protocol functions built on the foundation of get & Co.
Oh, and have a look at gvec.clj in Clojure's sources for an example of what some serious data structure code written using deftype might look like. The complexity here is of a different kind from what you describe in the question, but still, it's one of the few examples of custom data structure programming in Clojure currently available for public consumption (and it is of course excellent quality code).
Of course this is just what my intuition tells me at this time. I'm not sure that there is much in the way of established idioms at this stage, what with deftype not actually having been released and all. :-)

How to create data structure in Tcl?

I am translating some lisp code to Tcl and wonder if there is anything like lisp's defstruct in Tcl for creating data structures?
If nothing is built into Tcl, what extension packages to Tcl would you recommend that can be used in a commercial application.
Thanks.
-William
Consider using dictionaries, which work more or less like a hashmap. You can set the key/value pairs much like you would any other structure.
You could take a look at the pages on Rosetta Code under Data Structures. They all have Tcl examples.
Tcl tutor is having 44-47 lessons on dictionaries.

What tools for migrating programs from a platform A to B

As a pet project, I was thinking about writing a program to migrate applications written in a language A into a language B.
A and B would be object-oriented languages. I suppose it is a very hard task : mapping language constructs that are alike is doable, but mapping libraries concepts will be a very long task.
I was wondering what tools to use, I know this has to do with compilation, but I'm a bit afraid to use Lex and Yacc and all that stuff.
I was thinking of maybe using the Eclipse Modeling Framework, which would help me write models (of application code) transformations in a readable form.
But first I would have to write parsers for creating the models (and also create the metamodel from the language grammar).
Are there tools that exist that would make my task easier?
You can use special transformation tools/languages for that TXL or Stratego/XT.
Also you can have a look and easily try Java to Python and Java to Tcl migrating projects made by me with TXL.
You are right about mapping library concepts. It is rather hard and long task. There are two ways here:
Fully migrate the class library from language A to B
Migrate classes/functions from language A to the corresponding concepts in language B
The approach you will choose depends on your goals and time/resources available. Also in many cases you wont be doing a general A->B migration which will cover all possible cases, you will need just to convert some project/library/etc. so you will see in your particular cases what is better to do with classes/libraries.
I think this is almost impossibly hard, especially as a personal project. But if you are going to do it, don't make life even more difficult for yourself by trying to come up with a general solution. Choose two specific real-life programming languages ind investigate the possibities of converting between them. I think you will be shocked by the number of problems and issues this will expose.
There are some tools for direct migration for some combinations of A and B.
There are a variety of reverse engineering and code generation tools for different languages and platforms. It's fairly rare to see reverse engineering tools which capture all the semantics of the source language, and the semantics of UML are not well defined ( since it's designed to map to different implementation languages, it itself doesn't define a complete execution model for its behavioural representations ), so you're unlikely to be able to reverse engineer and generate code between tools. You may find one tool that does full reverse engineering and full code generation for your A and B languages, and so may be able to get somewhere.
In general you don't use the same idioms on different platforms, so you're more likely to get something which emulates A code on B rather than something which corresponds to a native B solution.
If you want to use Java as the source language(that language you try to convert) than you might use Checkstyle AST(its used to write Rules). It gives you tree structure with every operation done in the source code. This will be much more easier than writing your own paser or using regex.
You can run com.puppycrawl.tools.checkstyle.gui.Main from checkstyle-4.4.jar to launch Swing GUI that parse Java Source Code.
Based on your comment
I'm not sure yet, but I think the source language/framework would be Java/Swing and the target some RIA language like Flex or a Javascript/Ajax framework. – Alain Michel 3 hours ago
Google Web Toolkit might be worth a look.
See this answer: What kinds of patterns could I enforce on the code to make it easier to translate to another programming language?

Resources