Results 1 to 8 of 8

Thread: Pass or change TYPE in other unit, possible?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    I quicky checked what std::map is. I haven't used it before.
    If I understand it correctly it is quite similar to word compression. It scans you data to find all posible variations of posible data blocks, builds some kind of a dictionary which contains all posible data block variations and then finally replaces these datablocks with index numbers which represent the block variation saved in this "dictionary".
    In word compression with using 16 bit integer number for dictionary Index this means that you can compress any word which is more than 3 characters long and ocurs athleast twice in the text.

    I'm still puzled why you need ability of direct typecasting from String to Integer and vice versa.

    Also if you might share how you store your map data I might provide you with an alternative solution for compressing map data.

  2. #2
    Its too long to explain. But in short: std::map only stores unique keys.
    It needs custom comparators for custom structs (records). It provides his own comparators for simple types like int, float etc.

    And the primary thing in map compression is unique blocks and columns. And it must be fast.
    I already use std::map for compression and its fast, i just created a DLL in C++ and pass the map array data (actually pointer) to DLL and it compresses it.
    This all works fine and i can live with DLLs, i use SDL and other things anyway that are in DLLs.

    But i just wanted to include it in my code, to get rid of the C++ DLL. Then i can also prove myself that std::map kind of "thingy" is possible in Delphi (Pascal) also.
    Sadly without generics in older versions.

    Take it as an exercise for me. I need one "map" for blocks and one "map" for columns. Currently i created 2 units in Delphi, one for blocks and one for columns.
    As you see, without generics, code is duplicated.

    Dont worry, i will first finish the compressor in FreePascal, to see if it even finds the correct unique columns and compresses map correctly.
    Because i tried many things already in Delphi 7, DeCAL, dcl, etc.. All of them have trouble finding me correct unique blocks and same with columns. All are wrong (ok a bit wrong, but if one is wrong, then whole map is wrong. And will crash the game).

    Probably because most of these container libs to not support (custom) comparators, otherwise even std::map doesnt know whats unique block or column and which is not.
    And of course column struct is a bit complicated also (it contains small static array in it).


    So, i will try to port this to FPC first (actually i already did, but its unfinished).
    If it works, then i will see what i will do next with it.

  3. #3
    not sure if it applies, but have you considered to use variants?

  4. #4
    I guess you could try using includes and macros. Divide the thing into two files: one include file, which will contain the map code, and one (or more) files defining macros and including the map code.

    For example:
    map.inc
    Code:
    Type TMap = class
       { snip }
       Procedure Insert(Key: KEYTYPE ; Val : VALUETYPE );  
       Function Search(Key: KEYTYPE ): VALUETYPE ;
       { snip }
    map_blocks.pas
    Code:
    unit map_blocks;
    
    {$MACRO ON} {$DEFINE KEYTYPE:=TMyCoord} {$DEFINE VALUETYPE:=TMyBlock}
    
    {$INCLUDE map.inc}

  5. #5
    Macros are only in FPC it seems, sadly no such thing in D7.
    In FPC, i will try this of course..

    I once found even some IDE plugin or addon or something, that kinda tried to make things generic in old Delphi. D5 or something.
    You specified type you wanted and it generated another unit with this type and it used it..

    I must find it, it was interesting. Probably from archives, the website is gone.


    Can the "records" work with variants, i mean can they work together?
    Last edited by hwnd; 17-12-2013 at 10:29 PM.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •