Linux C or C++ library to diff and patch strings? [closed] - c++

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 7 years ago.
Improve this question
Possible Duplicate:
Is there a way to diff files from C++?
I have long text strings that I wish to diff and patch. That is given strings a and b:
string a = ...;
string b = ...;
string a_diff_b = create_patch(a,b);
string a2 = apply_patch(a_diff_b, b);
assert(a == a2);
If a_diff_b was human readable that would be a bonus.
One way to implement this would be to use system(3) to call the diff and patch shell commands from diffutils and pipe them the strings. Another way would be to implement the functions myself (I was thinking treat each line atomically and use the standard edit distance n^3 algorithm linewise with backtracking).
I was wondering if anyone knows of a good Linux C or C++ library that would do the job in-process?

You could google implementation of Myers Diff algorithm. ("An O(ND) Difference Algorithm and Its Variations") or libraries that solve "Longest common subsequence" problem.
As far as I know, the situation with diff/patch in C++ isn't good - there are several libraries (including diff match patch, libmba), but according to my experience they're either somewhat poorly documented or have heavy external dependencies (diff match patch requires Qt 4, for example) or are specialized on type you don't need (std::string when you need unicode, for example), or aren't generic enough, or use generic algorithm which has very high memory requirements ((M+N)^2 where M and N are lengths of input sequences).
You could also try to implement Myers algorithm ((N+M) memory requirements) yourself, but the solution of problem is extremely difficult to understand - expect to waste at least a week reading documentation. Somewhat human-readable explanation of Myers algorithm is available here.

I believe that
https://github.com/cubicdaiya/dtl/wiki/Tutorial
may have what you need

http://code.google.com/p/google-diff-match-patch/
The Diff Match and Patch libraries offer robust algorithms to perform the operations required for synchronizing plain text.
Currently available in Java, JavaScript, Dart, C++, C#, Objective C, Lua and Python. Regardless of language, each library features the same API and the same functionality. All versions also have comprehensive test harnesses.

Related

How to read/interrogate a filesystem and file structure [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 4 years ago.
Improve this question
As a first time programming using vi with a raw Linux terminal in C++, what is the simplest way to recurse through a filesystem and get results such as file size, date, directory date etc?
I imagine I'm missing a library or two that would handle this pretty cleanly which would be great to know. Even better would be knowing where to find a solid reference for the basics like this.
If you have a modern compiler you can use std::filesystem:
https://en.cppreference.com/w/cpp/filesystem
Otherwise you can use boost::filesystem, which is very similar but non standard:
https://www.boost.org/doc/libs/1_67_0/libs/filesystem/doc/index.htm
Boost is a collection of libraries with various purposes and a focus on quality. Boost libraries regularly end up in the new C++ standards so it's good thing to learn.
You might consider (on Linux at least) to use nftw(3). You could use opendir(3) + readdir(3) + closedir with stat(2) (and nftw is using all these). See also syscalls(2) (and read some Linux programming book, perhaps the old ALP). Notice that on Linux (and POSIX systems), the operating system API is in C, not in C++.
Of course, you might use the C++ functions given in f4's answer (they are are based on functions above).
And you could use C++ frameworks such as boost, poco, Qt (also using the functions above).

Library for Trust-Region Reflective algorithms in C [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 3 years ago.
Improve this question
I'm trying to rebuild some Matlab code in C that uses their fsolve function. From the documentation it's using a "trust region reflective" algorithm (I already built it using a Levenberg-marquardt algorithm and it's converging completely differently). Can anyone recommend a library for doing this type of optimization in C/C++ ?
Not sure what "reflective" adds to the "trust region" definition. However, Knitro is a powerful trust-region interior-point optimizer with a C/C++ interface. Unfortunately, Knitro is only available without cost in a limited edition for students; the full version requires a commercial license.
There is also Ipopt, which is not trust-region but nevertheless a powerful C/C++ based large-scale nonlinear constrained optimization engine with an open-source license.
Have you tried checking if your function is convex, if LM and some other convex optimization algorithm converge differently, there is a good chance that the base function is not convex. Also have you checked if the cost function is at least of order 2. If this is the case minimizing the square of the cost function can be better than minimizing the cost function alone.
There are two types of general-purpose algorithms for which there is a global convergence guarantee (under standard assumptions, don't ask :) ). These methods are the line search and the trust region methods. If you wish, you can read more on this topic in the book of Nocedal-Wright: Numerical Optimization.
I haven't tried Knitro recently.
Ipopt is the most robust solver among those I have tried, I highly recommend it. It implements the line search method and is written in C++.

MATLAB code library for C++ [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 6 years ago.
Improve this question
Are there any good sources containg C++ versions of MATLAB functions? I am only looking for some basic functions i.e. fzero.
fzero is non trivial.
If your function is polynomial, try GSL http://www.gnu.org/software/gsl/
Try looking at GNU Octave. It's a FLOSS alternative to MATLAB and has a lot of the same functionality. Take a look at its implementation of fzero, keeping in mind that the code is GPL'ed.
I do a lot of work in C++ for science and engineering applications. One of my favorite references is Numerical Recipes nr.com. Some of the older versions of the book included code that looked like Fortran but was written in C, for example indexes of arrays started at 1. The latest version from 2007 (C++ only 3rd edition) corrected many of the complaints like 1 indexed arrays and confusing namespace. Even if you don’t like the code the simple explanations of the math make the book worth buying. Be warned some people consider the license for the code harsh but compared to Matlab it is a giant leap forward. Other things to try is GSL and Intel Math Kernel Lib. Good luck.
Check out the embedded matlab subset. It allows you to convert matlab scripts into C code. I use it to make libraries out of matlab functions which I link to form C++ projects. It only supports a subset of functions, but fzero is included in the list with some limitations . . .
http://www.mathworks.com/help/toolbox/eml/ug/bq1h2z7-9.html
This allows you to do all of your algorithmic development in the warm and cozy Matlab environment. Matlab will even build the C library. All you have to do is link to it. This is WAY easier than learning a bunch of C++ numerical libraries if you're already familiar with Matlab.
I don't think it contains an fzero equivalent, but Armadillo does have many C++ versions of MATLAB functions (so may do for some instances). See, for example, this conversion table.

advance mathematics c++ libraries [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 8 years ago.
Improve this question
what popular advance mathematics libraries for c++ are present out there, so that they can be used as a 1 stop solution and avoiding reinventing the wheel ?
Check out GNU Scientific Library -- it's in C, but I use it all the time to avoid re-writing the Numerical Recipes code.
Intel's MKL (Math Kernel Library) is to be looked at especially if doing large scale matrix operations; it's C based, but should not really be an issue IMO.
Other than that, maybe the boost math library could be interesting as it is free. (but I have no experience with it, so YMMV).
Max.
Like others have said, you will probably not find a single library to handle all of the areas you listed. For matrix algebra, I've heard good things about the Eigen C++ library from coworkers who are using it.
For commercial libraries, both NAG (Numerical Algorithms Group, http://www.nag.co.uk/) and IMSL ( http://www.vni.com/products/imsl/ ) are standards and provide industrial-strength numerical analysis algorithms.
look through the list and mix-and-match. You want very many things, unlikely any single package is going to do them all.
http://www.oonumerics.org/
octave is the only one that is going to be more or less comprehensive (functionality comparable/clone to Matlab)
http://www.mathias-michel.de/download/howto-octave-c++.ps
For group theory there is GAP.

Is there an STL and UTF-8 friendly C++ Wrapper for ICU, or other powerful Unicode library [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 7 years ago.
Improve this question
I need a good Unicode library for C++. I need:
Transformations in a Unicode sensitive way. For example sort all strings in a case insensitive way and get their first characters for index. Convert various Unicode strings to upper and to lower case. Split text at a reasonable position -- words that would work for Chinese and Japanese as well.
Formatting numbers, dates in locale sensitive way (should be thread safe).
Transparent support of UTF-8 (primary internal representation).
As far as I know the best library is ICU. However, I can't find normal developer friendly API documentation with examples. Also as far as I see, it is not too friendly with
modern C++ design, work with STL and so on. Like this:
std::string msg;
unistring umsg.from_utf8(msg);
unistring::word_iterator wi;
for(wi=umsg.words().begin(),n=0;wi!=usmg.words().wi_end(),n<10;++wi,++n)
;
msg=umsg.substr(umsg.words().begin(),wi).to_utf8();
cout<<_("Five 10 words are ")<<msg;
Is there a good STL friendly ICU wrapper released under Open Source license? Preferred is a license permissive like MIT or Boost, but others, like LGPLv2 compatible, are OK as well.
Is there another high quality library similar to ICU?
Platform: Unix/POSIX, Windows support is not required.
Edit: unfortunately I wasn't logged in, so I can't make accept an answer. I have attached the answer by myself.
This question was asked quite a long time before by myself. There was no such library.
So I had written C++ friendly Boost.Locale library that wraps ICU.
Docs: http://cppcms.sourceforge.net/boost_locale/html/
Sources: https://sourceforge.net/projects/cppcms/files/
Edit Now part of Boost: see Boost.Locale documentation
The wxWidgets GUI toolkit has some rather nice string classes and unicode support. You don't need to build/use GUI classes if you don't want to. See here for details.
Does this fit the bill?
http://www.codeproject.com/KB/string/utf8cpp.aspx